diff --git a/code/client/launchapp b/code/client/launchapp new file mode 100755 index 00000000..c635c9f8 --- /dev/null +++ b/code/client/launchapp @@ -0,0 +1,60 @@ +#!/usr/bin/python +# encoding: utf-8 +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +launchapp + +Created by Greg Neagle on 2010-02-05. +Launches an app only if we're called in the current +GUI user's session. +Prevents multiple copies of the app from being launched +when Fast User Switching is in use +""" + +import sys +import os +import optparse +import subprocess + + +def getconsoleuser(): + from SystemConfiguration import SCDynamicStoreCopyConsoleUser + cfuser = SCDynamicStoreCopyConsoleUser( None, None, None ) + return cfuser[0] + + +def main(): + consoleuser = getconsoleuser() + try: + thisuser = os.environ['USER'] + except: + # when run via launchd at loginwindow context, os.environ['USER'] + # is undefined, so we'll return root (the effective user) + thisuser = "root" + + if (consoleuser == thisuser) or \ + (consoleuser == None and thisuser == "root"): + p = optparse.OptionParser() + options, arguments = p.parse_args() + try: + app = arguments[0] + except: + print >>sys.stderr, "Must specify an app to launch!" + exit(-1) + retcode = subprocess.call(["/usr/bin/open", "-a", app]) + exit(retcode) + + +if __name__ == '__main__': + main() + diff --git a/launchd/LaunchAgents/com.googlecode.munki.ManagedSoftwareUpdate.plist b/launchd/LaunchAgents/com.googlecode.munki.ManagedSoftwareUpdate.plist index a5f92833..bfc8a3f3 100644 --- a/launchd/LaunchAgents/com.googlecode.munki.ManagedSoftwareUpdate.plist +++ b/launchd/LaunchAgents/com.googlecode.munki.ManagedSoftwareUpdate.plist @@ -10,8 +10,7 @@ ProgramArguments - /usr/bin/open - -a + /usr/local/munki/launchapp Managed Software Update RunAtLoad diff --git a/launchd/LaunchAgents/com.googlecode.munki.munkistatus.plist b/launchd/LaunchAgents/com.googlecode.munki.munkistatus.plist index de7b5976..6b9f822b 100644 --- a/launchd/LaunchAgents/com.googlecode.munki.munkistatus.plist +++ b/launchd/LaunchAgents/com.googlecode.munki.munkistatus.plist @@ -11,6 +11,7 @@ ProgramArguments + /usr/local/munki/launchapp /Library/Application Support/Managed Installs/MunkiStatus.app/Contents/MacOS/MunkiStatus RunAtLoad