Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to run applescript at startup?

Hello,

I'm looking to find out how to run a script at startup. I have found this thread, but the second/last post seems to have some foreign characters in the code, and where do you store the script (roots home)?

thread reference = http://applescript.net/viewtopic.php?id=9054


Thanks
Dave

G5 dual 1.8/1gig Mac OS X (10.4.6)

Posted on Jul 7, 2006 8:46 AM

Reply
7 replies

Jul 7, 2006 9:56 AM in response to David Boyer2

Just delete those illegal characters, save your script as an application in the applications folder. and run the script with the appropriate name for the application.

Or if you do not want to run this script or cant get it to work, just simply save your script as an application. Then open System Preferences > accounts > login items, then select the add option (small plus sign) and select your application.

Jul 7, 2006 7:58 PM in response to David Boyer2

You can launch osascript by way of StartupItems, but of security, you will have to do lotsa maunal work. Run the following script:'

--begin
set nl to ASCII character 10
set _name to text returned of (display dialog "Name of Startup Item:" default answer "")

tell application "Finder"
try
set new_folder to (make new folder at desktop with properties {name:_name}) as string
end try
end tell

set shell_contents to "#!/bin/sh" & nl & nl & "/usr/bin/osascript "
do shell script "/bin/echo " & quoted form of shell_contents & " > " & quoted form of (POSIX path of (new_folder & _name))

set plist_contents to "{" & "
Description = \"" & _name & "\";" & nl & "}"
do shell script "/bin/echo " & quoted form of plist_contents & " > " & quoted form of (POSIX path of (new_folder & "StartupParameters.plist"))
--end

it'll prompt for the Startup Item name. <folder name>
it'll create a folder on your desktop with specified name, the folder contains two text files.
leave the StartupParameters.plist alone, you need to edit the other file
open other file with TextEdit, you find:

#!/bin/sh
/usr/bin/osascript


you have to append POSIX path of your script in quoted form to after /usr/bin/osascript . ie: /usr/bin/osascript '/blah/blah blah'

move (copy) the folder to '/Library/StartupItems/' folder

now you have to chmod and chown for the folder, in Terminal:

sudo chmod -R 755 /Library/StartupItems/ <folder name>
sudo chown -R root:wheel /Library/StartupItems/ <folder name>

Sep 6, 2006 1:16 AM in response to David Boyer2

I have a shell script to run at startup. I did this by putting appropriate files into the directory

/Library/StartupItems

I believe that you could arrange to run an Apple script at startup in just the same way. An admin user can put things into the /Library. However some of the things you will have to do must be done as 'superuser' using the sudo command -- so be careful.

I wanted a firewall setup different from the ones Apple provides for simply through System Prefs. So I made a directory

/Library/StartupItems/Firewall

with permissions drwxr-xr-x owned by root and group being wheel.

I put two files in this directory. One of these is my script for starting up the firewall. In your case this would be your applescript saved as an application. The second file is a .plist file. This has to be written with some care, in ascii. My .plist file is like this:

<?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>Description</key>
<string>Firewall</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting firewall</string>
<key>stop</key>
<string>Stopping firewall</string>
</dict>
<key>OrderPreference</key>
<string>Late</string>
<key>Provides</key>
<array>
<string>Firewall</string>
</array>
<key>Requires</key>
<array>
<string>NetworkExtensions</string>
<string>Resolver</string>
</array>
</dict>
</plist>

Basically the .plist file (which must be named StartupParameters.plist)
contains information about when, during the boot process, your script should be launched.

It took me a while to work this out. Originally I had expected to be using launchd for this: but it that did not seem to work. Hence this method, which is really the same as used to work in Panther. Hope this helps!

Sep 11, 2006 10:36 AM in response to David Boyer2

Hi,

If you want your applescript to run prior to login, then use launchd (OS X 10.4 or greater).

Save the applescript as an application and then use Lingon and the Macworld article (link below) to set up a launchd job that will run prior to login.

http://www.macworld.com/2006/01/secrets/februarygeekfactor/index.php
http://www.macworld.com/2005/12/secrets/febgeekfactorside/index.php
http://lingon.sourceforge.net/

HTH

Vince

G5 Quad

How to run applescript at startup?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.