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)?
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.
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:
Save your script as an application. Then open system prefs go to accounts then login items, after unlocking the panel hit the + sign and locate the Applescript application that you saved and enter it in the list.
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:
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!