Reputation: 11
I have written an AppleScript and want to convert it to an osascript so I can run it on launch using launchd. Is there any way I can convert this to osascript or do I have to rewrite the whole script as an osascript? If it can't be done is there at least a way to run it as osascript in the terminal? Thank you!
on idle
tell application "System Events" to ¬
if exists process "Launchpad" then run script
tell application "Launchpad"
delay 0
tell application "System Events" to keystroke "b" using {control down, option down, command down}
delay 0
tell application "System Events" to keystroke "b" using {control down, option down, command down}
delay 0
tell application "System Events" to keystroke "b" using {control down, option down, command down}
delay 0
end tell
end idle
Upvotes: 1
Views: 2056
Reputation: 27613
If you only need to run it once per second or less frequently, you could save it as a normal script:
tell application "System Events"
if not (exists process "Launchpad") then return
repeat 3 times
keystroke "b" using {control down, option down, command down}
end repeat
end tell
And repeat running the script with launchd:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.stackoverflow.11945633</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/username/Library/Scripts/script.scpt</string>
</array>
<key>StartInterval</key>
<integer>1</integer>
</dict>
</plist>
The property list has to be loaded manually with launchctl load ~/Library/LaunchAgents/com.stackoverflow.11945633.plist
. Applying changes requires unloading and loading it.
Programs are sent a SIGKILL signal after 20 seconds by default. You can override the timeout by adding an ExitTimeOut
key. See man launchd.plist
.
The script doesn't actually work for changing the Launchpad background. Launchpad.app is just a dummy application that quits immediately when it's opened.
If you just want to change the background style, you can do it with defaults write com.apple.dock springboard-background-filter -int 2; killall Dock
.
Upvotes: 1