Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allthingsgo/e428fb81f8206a94bf52f9b5f2c2f598 to your computer and use it in GitHub Desktop.
Save allthingsgo/e428fb81f8206a94bf52f9b5f2c2f598 to your computer and use it in GitHub Desktop.
Launchctl-use-cases
#!/bin/bash
#Script loads the deployed user.launchkeep.GoogleDrive.plist that came from a Casper PKG. Using because Google Drive is randomly crashing on end-user devices.
#Get User Name
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'`
#Confirms working
echo $loggedInUser
#Need to kill Google Drive - found is open load the .plist, the Google Drive Finder window continiously opens.
killall Google\ Drive
sleep 5s
#moves the .plist to user's folder & ensures correct permissions.
sudo -u $loggedInUser mkdir /Users/$loggedInUser/Library/LaunchAgents
cp /var/mbca/user.launchkeep.GoogleDrive.plist /Users/$loggedInUser/Library/LaunchAgents
chown -R $loggedInUser /Users/$loggedInUser/Library/LaunchAgents
chmod 744 /Users/$loggedInUser/Library/LaunchAgents
#user needs to be able to rx the script
chmod 755 /private/var/mbca/KeepGoogleDriveAlive.sh
#loads the .plist. Must be loaded as the user, not root.
sudo -u $loggedInUser launchctl load /Users/$loggedInUser/Library/LaunchAgents/user.launchkeep.GoogleDrive.plist
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment