Skip to content

Instantly share code, notes, and snippets.

@kcrawford
Created April 27, 2013 20:41
Show Gist options
  • Save kcrawford/5474622 to your computer and use it in GitHub Desktop.
Save kcrawford/5474622 to your computer and use it in GitHub Desktop.
postflight installer script to reload a LaunchAgent
#!/bin/bash
# if someone is logged in
if who | grep -q console; then
# get the logged in user's uid
LOGGED_IN_UID=`ls -ln /dev/console | awk '{ print $3 }'`
# use the uid and pgrep to find the Finder process id
FINDER_PID=`pgrep -U ${LOGGED_IN_UID} Finder`
# use launchctl bsexec to run applescript code in the same Mach bootstrap namespace hierachy as the Finder
launchctl bsexec "${FINDER_PID}" osascript -e '
tell app "Finder"
do shell script "
launchctl unload -S Aqua /Library/LaunchAgents/com.company.agent.plist
launchctl load -S Aqua /Library/LaunchAgents/com.company.agent.plist
"
end tell
'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment