Last active
June 22, 2020 16:41
-
-
Save eahrold/8343361 to your computer and use it in GitHub Desktop.
Launch App At Login via LaunchAgent py (for munki)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import plistlib | |
from os import seteuid | |
from ServiceManagement import * | |
from SystemConfiguration import SCDynamicStoreCopyConsoleUser | |
installdir = 'Applications' | |
launchapp = 'AppName' | |
launchd = 'com.launchd.revdomain' | |
def main(): | |
#write out the LaunchDaemon Plist | |
launchd_file = '/Library/LaunchAgents/'+launchd+'.plist' | |
program = '/'+installdir+'/'+launchapp+'.app/Contents/MacOS/'+launchapp | |
launchd_plist = {'Label':launchd, | |
'Program':[program], | |
'RunAtLoad':True, | |
'KeepAlive':{'SuccessfulExit':True}, | |
} | |
plistlib.writePlist(launchd_plist,launchd_file ) | |
#fix the permissions | |
subprocess.call(['/usr/sbin/chown','root:wheel',launchd_file]) | |
subprocess.call(['/bin/chmod','0644',launchd_file]) | |
cfuser = SCDynamicStoreCopyConsoleUser( None, None, None ) | |
if cfuser[0]: | |
seteuid(cfuser[1]) | |
SMJobSubmit(kSMDomainUserLaunchd,launch_agent,None,None) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am wondering where the "launch_agent" variable was defined the one referenced in the SMJobSubmit command. Do you have an updated version of this script please?