• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Automatically launch GUI app for current and future users
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatically launch GUI app for current and future users


  • Subject: Re: Automatically launch GUI app for current and future users
  • From: Per Olofsson <email@hidden>
  • Date: Thu, 16 Feb 2012 09:05:55 +0000
  • Thread-topic: 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      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Automatically launch GUI app for current and future users (From: Per Olofsson <email@hidden>)

  • Prev by Date: Re: mac os packaging. per-user data deployment
  • Previous by thread: Re: Automatically launch GUI app for current and future users
  • Next by thread: Meta Package How-To
  • Index(es):
    • Date
    • Thread