Make the file executable:

chmod +x ~/


Using launchd Create a file: (~)/Library/LaunchAgents/com.script.startCam.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

The following example shows a complete job definition with only three keys:

  • Label This key is required for every job definition. It identifies the job and has to be unique for the launchd instance. Theoretically it is possible for an agent to have the same label as a daemon, as daemons are loaded by the root launchd whereas agents are loaded by a user launchd, but it is not recommended.
  • Program This key defines what to start, in this case a shell script /Users/Me/Scripts/
  • RunAtLoad This is one of several optional keys specifying when the job should be run, in this case right after it has been loaded.

Now, let’s add it as a Login Hook:

sudo defaults write LoginHook /usr/local/bin/ 
sudo defaults write LogoutHook /usr/local/bin/
sudo defaults delete LoginHook
sudo defaults delete LogoutHook