Run AppleScript on startup (background)

7

3

I want to run a apple-script on Mac OS X on startup. The script shall run during the complete lifetime of the user session.

What is the best solution to do this?

My Script:

on idle
    do shell script "/usr/local/bin/wol -p 9 0:1d:63:19:b7:32"
    delay 120
end idle

Any help will be very appreciated.

road242

Posted 2010-01-23T19:34:39.830

Reputation: 648

Answers

10

When saving the script in the script editor, save as an application bundle, then add it to the startup items in login system preferences:

alt text

If you want it to run in the background, you can use iBackground Scripts, a free tool to make applescripts run in the background.

alt text

John T

Posted 2010-01-23T19:34:39.830

Reputation: 149 037

Thanks for your response. I've already done that. The problem is, that the apple script will be display in the dock during the complete user session. Is there any way to get rid of the apple script symbol in the dock? – road242 – 2010-01-23T19:46:18.117

1Just added that info :) – John T – 2010-01-23T19:47:12.793

Thanks again. Works fine and runs in background.

But I'm asked if I want to run the script on startup. Is there a way to avoid the question dialog? – road242 – 2010-01-23T20:11:27.587

Hmm. Maybe another applescript to tell it "yes" would do? – John T – 2010-01-23T20:14:47.020

8

I know your question is about running an Apple Script, but if all the script is doing is running /usr/local/bin/wol every 2 minutes, a simpler solution might be to use a launch daemon?

Either in /Library/LaunchDaemons if it's to run continuously even without a user logged in, or in ~/Library/LaunchDaemons to run per user (bearing in mind there could be more than one instance running if you've got more than one user logged in).

At least you don't have to worry about popup windows getting in the way.

Steve Folly

Posted 2010-01-23T19:34:39.830

Reputation: 5 293

2

As an alternative to the AppleScript way, I typically use launchd for handling things like this. launchd is customizable and very powerful.

http://developer.apple.com/MacOsX/launchd.html

Mark Suman

Posted 2010-01-23T19:34:39.830

Reputation: 121

1

To prevent the 'do you want to run...' dialog: As you're saving your script as an application bundle, untick the 'Startup Screen' checkbox in the Save As dialog.

JRobert

Posted 2010-01-23T19:34:39.830

Reputation: 6 128