Re: Automatically launch GUI app for current and future users
8 feb 2012 kl. 13:11 skrev Per Olofsson:
I have written a status menu application that we're going to deploy internally, pushed with Munki as a silent background install. It needs to launch automatically for all users, both when new users log in, and for those who are already logged in - I'd rather not force a logout to activate it.
I ended up going with a launch agent, and the following postinstall script: #!/usr/bin/python import sys import subprocess import re import syslog AGENT_PATH = "/Library/LaunchAgents/se.gu.it.DAFGU-Migration-Status.plist" def log_init(ident): syslog.openlog(ident=ident, logoption=syslog.LOG_CONS | syslog.LOG_PERROR, facility=syslog.LOG_DAEMON) def log(prio, msg): syslog.syslog(prio, msg.encode("utf-8")) def log_info(msg): log(syslog.LOG_NOTICE, msg) def log_warn(msg): log(syslog.LOG_WARNING, msg) def log_error(msg): log(syslog.LOG_ERR, msg) re_login = re.compile(r'^(?P<username>\S+)\s+(?P<pid>\d+).+loginwindow.app', re.I) def main(argv): log_init("DAFGU Migration Status postinstall") # Make sure we're installing on a live system. if argv[3] != "/": log_info("Installing on %s, not a live system" % repr(argv[3])) return 0 else: log_info("Installing live system") # Get process list. p = subprocess.Popen(("/bin/ps", "auxww"), stdout=subprocess.PIPE) (out, _) = p.communicate() # Find all loginwindow processes. loginwindows = list() for line in out.splitlines(): m = re_login.search(line) if m: username = m.group("username") pid = int(m.group("pid")) loginwindows.append((username, pid)) # Load LaunchAgent in each user context. for (username, pid) in loginwindows: log_info("Loading launchagent for %s" % repr(username)) p = subprocess.Popen(("/bin/launchctl", "bsexec", str(pid), "chroot", "-u", username, "/", "launchctl", "load", AGENT_PATH, )) p.communicate() log_info("launchctl returned %d" % p.returncode) return 0 if __name__ == '__main__': sys.exit(main(sys.argv)) -- Per Olofsson, IT-service, University of Gothenburg _______________________________________________ Do not post admin requests to the list. They will be ignored. Installer-dev mailing list (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
Per Olofsson