7 Replies Latest reply: Dec 28, 2006 12:26 PM by David Boyer2
David Boyer2 Level 1 Level 1

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


G5 dual 1.8/1gig   Mac OS X (10.4.6)  
  • Richard Moore Level 3 Level 3
    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.
  • David Boyer2 Level 1 Level 1

    Thanks for your info. I was actually talking about running it before a user logs in. I think I found out how to do it using "osascript".

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

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

    tell application "Finder"
    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"))

    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:



    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>
  • fragmore Level 3 Level 3
    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.

    Simple eh!
  • MacPeter Level 2 Level 2
    I have a shell script to run at startup. I did this by putting appropriate files into the directory


    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


    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">
    <string>Starting firewall</string>
    <string>Stopping firewall</string>

    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!
  • Vincent Angeloni1 Level 1 Level 1

    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.




    G5 Quad    
  • David Boyer2 Level 1 Level 1
    Solved using LauchD