Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

quanganhct

macrumors member
Original poster
Dec 29, 2010
31
0
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
 
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.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.