Launchd to run script at start up

I have a script that I want to run at startup.

This is my plist

<?xml version="1.0" encoding="UTF-8"?> Label Start ProgramArguments /Library/Scripts/User/Wake.sh RunAtLoad KeepAlive

I’ve run
launchctl load /Library/LaunchDaemons/start.plist
from Terminal which runs the script successfully but the script doesn’t run on start up.

Any help appreciated, thanks.

Hello.

If you reread the manual you will find a -w switch, use this for loading. I am not sure if this is your real problem however. When I’m in doubt whether a launchd process is running, I include a line like.

touch ~/Desktop/isrunning.txt

Then I see wether the thing is running. If you are trying to run the script every time you login into your computer, and only that time, creating a login hook might be worth an investigation. Search for “login hook” here.

Hi,

I assume this should a user based launch daemon respective agent.
I assume also that the script should only be executed once at login.
Then you should install a user based launchd agent instead of a system based launchd daemon

So omit the KeepAlive parameter and save the script in your user library folder in the LaunchAgents folder.

With your environment launchctl doesn’t work, because you need sudo to affect daemons/agents in /Library and /System/Library

Hello.

I need more coffee. :slight_smile:
But I still thought you had to use the -w switch, but that was if you was to permanently unload it.

the -w switch affects only the Disabled key in the plist file.
it’s not required to load an agent/daemon immediately

Thanks to everyone that replied. I did what was written above and used the -w switch.

Thanks again.

Just my two cents,
isn’t it easier to install the script or an alias pointing to it in the list of Login Items during the Startup process.
This feature is ruled in the Preference Pane “Comptes” in French. I guess that it’s named “Users” in English.

I have four scripts in this list for years and everything behave flawlessly.

Yvan KOENIG (VALLAURIS, France) vendredi 13 août 2010 14:14:10

Hello.

I will add a couple of cents too. The login hook for login and logout items I described, which are installed via the defaults system are system wide, and are executed during login/logout which means that the need root rights, and are executed before any login items are executed. The logout hook is the last process run under logout.

There is also an utility which enables you to run processes every time the computer wakes or goes to sleep. This is stuff that a normal launchd process can’t handle as launchd doesn’t have events for the processor going to sleep and awakes from sleep and calls for a little unix utility named SleepWatcher which can be found via google.