Run a command on start up 1 time

Discussion in 'Mac Programming' started by quanganhct, Oct 17, 2011.

  1. quanganhct macrumors member

    Joined:
    Dec 29, 2010
    #1
    Hello,

    Here is my issue. I wanna run my script QAScript.sh on start up. So I follow every steps I found out ( abour launchd)

    This is my plist file :
    PHP:
    <?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>QAScript</string> <!-- org.mongodb.mongodb perhaps? -->

        <key>OnDemand</key>
        <false/>

        <key>UserName</key>
        <string>nguyenquanganh</string>

        <key>GroupName</key>
        <string>staff</string>

        <key>ProgramArguments</key>
        <array>
            <string>/Users/nguyenquanganh/QAScript.sh</string>
            <string>-</string>
        </array>
    </dict>
    </plist>
    However, I want that my script executed only one time, but it seem that it was executed continuously. So, Is there any way to make it fired just one time on start up ? Thanks a lot
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    OnDemand is deprecated, try replacing it with KeepAlive.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    OnDemand is the wrong key for launching once. The correct key is RunAtLoad.

    Quoting from the man page for launchd.plist:
    RunAtLoad <boolean>
    This optional key is used to control whether your job is launched once at
    the time the job is loaded. The default is false.
     
  4. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #4
    Your <label> should exactly match the filename of the plist, minus the '.plist' at the end. Otherwise you can get launchd very confused and unable to unload or reload your item.
     
  5. quanganhct thread starter macrumors member

    Joined:
    Dec 29, 2010
    #5
    I tried KeepALive = false too, but it's still not working.
     
  6. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #6
    If you just want your script to run once every time you log in, you can add it to login items in system preferences / accounts and forget about launchd.
     

Share This Page