Cómo evitar que el agente de inicio inicie repetidamente un AppleScript dado

3

Estoy intentando crear un agente de inicio, que lanza un AppleScript cada vez que se conecta un mouse. Similar a estas dos preguntas:

Sin embargo, una vez que cargue mi agente de inicio (a través de launchctl load ), se sigue iniciando cada 5 o más segundos. ¿Cómo me aseguro de que el agente se ejecute solo una vez, cuando el mouse esté conectado?

Aquí está mi agente (plist):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>com.automations.switchscrolldirection</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>/Users/lirik/Documents/Automation/SwitchScrollDirectionOnMouseEvent.scpt</string>
    </array>
    <key>LaunchEvents</key>
    <dict>
        <key>com.apple.iokit.matching</key>
        <dict>
            <key>com.apple.device-attach</key>
            <dict>
                <key>idProduct</key>
                <integer>49277</integer>
                <key>idVendor</key>
                <integer>1133</integer>
                <key>IOProviderClass</key>
                <string>IOUSBDevice</string>
                <key>IOMatchStream</key>
                <true/>
                <key>IOMatchLaunchStream</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

El AppleScript en cuestión:

on gamingMouseIsAttached()
    tell application "System Preferences"
        activate
        set current pane to pane "com.apple.preference.mouse"
    end tell
    tell application "System Events" to tell process "System Preferences"
        repeat until exists checkbox 1 of window "Mouse"
        end repeat
        tell checkbox 1 of window "Mouse" to if value is 1 then click
    end tell
    tell application "System Preferences" to quit
end gamingMouseIsAttached

on TrackpadIsAttached()
    tell application "System Preferences"
        activate
        set current pane to pane "com.apple.preference.trackpad"
    end tell
    tell application "System Events" to tell application process "System Preferences"
        repeat until exists checkbox 1 of tab group 1 of window "Trackpad"
        end repeat
        tell checkbox 1 of tab group 1 of window 1 to if value is 0 then click
    end tell
    tell application "System Preferences" to quit
end TrackpadIsAttached

tell current application
    delay 15
    set internalTrackpad to (do shell script "system_profiler SPUSBDataType | awk '/Trackpad:/ { print \"Internal Trackpad\" }'")
    set gamingMouse to (do shell script "system_profiler SPUSBDataType | awk '/Gaming Mouse G502:/ { print \"Gaming Mouse\" }'")

    if gamingMouse is equal to "" then
        if internalTrackpad is equal to "Internal Trackpad" then
            my TrackpadIsAttached()
            return
        end if
    end if

    if gamingMouse is equal to "Gaming Mouse" then
        my gamingMouseIsAttached()
        return
    end if
end tell
    
pregunta Kiril 09.01.2017 - 11:53

0 respuestas

Lea otras preguntas en las etiquetas