Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
postflight installer script to reload a LaunchAgent
# 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/
launchctl load -S Aqua /Library/LaunchAgents/
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment