Exemplo n.º 1
0
def log_std(msg):
	from AppKit import NSAlert, NSInformationalAlertStyle, NSRunningApplication, NSApplicationActivateIgnoringOtherApps

	# initialize
	# tip from: http://graphicsnotes.blogspot.fr/2010/01/programmatically-creating-window-in-mac.html
	NSApplication.sharedApplication()
	NSRunningApplication.currentApplication().activateWithOptions_(NSApplicationActivateIgnoringOtherApps);

	alert = NSAlert.alloc().init()
	alert.autorelease()
	alert.setAlertStyle_(NSInformationalAlertStyle)
	alert.setMessageText_(msg)
	alert.runModal()
Exemplo n.º 2
0
    def _terminiate_processes(cls, bundle_identifier):
        _log.info("Closing all terminating all processes with the bundle identifier %s" % bundle_identifier)
        from AppKit import NSRunningApplication

        processes = NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundle_identifier)
        for process in processes:
            process.terminate()
Exemplo n.º 3
0
 def still_running(cls, apps):
     result = []
     for app in apps:
         r = NSRunningApplication.runningApplicationsWithBundleIdentifier_(app.identifier)
         if r.count() > 0:
             result.append(app)
     return result
 def closeBrowsers(self):
     _log.info('Closing all existing safari processes')
     safariInstances = NSRunningApplication.runningApplicationsWithBundleIdentifier_('com.apple.Safari')
     for safariInstance in safariInstances:
         safariInstance.terminate()
     if self.safariProcess:
         _log.info('Safari process console output:\nstdout: %s\nstderr: %s' % self.safariProcess.communicate())
         if self.safariProcess.returncode:
             _log.error('Safari Crashed!')
Exemplo n.º 5
0
def get_executable_path():
    # Try to get the path from Cocoa
    r_app = NSRunningApplication.currentApplication()
    if r_app.bundleIdentifier().endswith(".ComputerTime"):
        path = r_app.executableURL().path()
    else:
        # Fallback to python script path
        path = os.path.abspath(__file__)
        logging.info("script file: %s", __file__)
    return path
Exemplo n.º 6
0
 def _terminate_processes(cls, process_name, bundle_id):
     from AppKit import NSRunningApplication
     _log.info('Closing all processes with name %s' % process_name)
     for app in NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundle_id):
         app.terminate()
         # Give the app time to close
         time.sleep(2)
         if not app.isTerminated():
             _log.error("Terminate failed.  Killing.")
             subprocess.call(['/usr/bin/killall', process_name])
Exemplo n.º 7
0
def get_bundle_identifier(pid=None):
    """
    Get bundle identifier for the given process identifier.

    if pid is None, the current process pid is used.
    """
    if pid is None:
        pid = os.getpid()
    app = NSRunningApplication.runningApplicationWithProcessIdentifier_(pid)
    if app is None:
        return
    return app.bundleIdentifier()
Exemplo n.º 8
0
 def closeBrowsers(self):
     _log.info('Closing all existing safari processes')
     safariInstances = NSRunningApplication.runningApplicationsWithBundleIdentifier_(
         'com.apple.Safari')
     for safariInstance in safariInstances:
         safariInstance.terminate()
     if self.safariProcess:
         _log.info(
             'Safari process console output:\nstdout: %s\nstderr: %s' %
             self.safariProcess.communicate())
         if self.safariProcess.returncode:
             _log.error('Safari Crashed!')
Exemplo n.º 9
0
    def __init__(self, domain=None, name=None):
        if not (domain or name):
            raise Exception('Name or domain must be provided')

        self.domain = domain
        self.prefs = Prefs(self.domain)
        self.apps = NSRunningApplication.runningApplicationsWithBundleIdentifier_(self.domain)

        if self.apps:
            self.app = self.apps[0]
            name = name or self.app.localizedName()

        self.name = name
Exemplo n.º 10
0
 def stop(self):
     try:
         self.mouse_listener.stop()
         self.kb_listener.stop()
         for app in NSRunningApplication.runningApplicationsWithBundleIdentifier_(
                 MOONLIGHT_BUNDLE_ID):
             count = 0
             pid = app.processIdentifier()
             while count < 30 and pid_exists(
                     pid):  # app.isTerminated() is always false.
                 app.forceTerminate()
                 sleep(1)
                 count += 1
     except Exception:
         logger.exception('Failed to stop Moonlight.')
Exemplo n.º 11
0
 def closeBrowsers(self):
     _log.info('Closing all existing safari processes')
     safariInstances = NSRunningApplication.runningApplicationsWithBundleIdentifier_(
         'com.apple.Safari')
     for safariInstance in safariInstances:
         safariInstance.terminate()
Exemplo n.º 12
0
#!/usr/bin/python

from AppKit import NSWorkspace
from AppKit import NSRunningApplication

ws = NSWorkspace.sharedWorkspace()
launchedApps = ws.launchedApplications()

appsToTerminate = []

# find apps, do not close Finder and frontmost app
for app in launchedApps:
	pid = app['NSApplicationProcessIdentifier']
	runningApp = NSRunningApplication.runningApplicationWithProcessIdentifier_(pid)
	
	if runningApp.bundleIdentifier() != 'com.apple.finder' and not runningApp.isActive():
		appsToTerminate.append(runningApp)

# close specified apps
for app in appsToTerminate:
	app.terminate()
	
print '%d apps terminated! Have a nice day!' % len(appsToTerminate)
	
Exemplo n.º 13
0
 def closeBrowsers(self):
     _log.info('Closing all existing chrome processes')
     chromes = NSRunningApplication.runningApplicationsWithBundleIdentifier_(
         'com.google.Chrome')
     for chrome in chromes:
         chrome.terminate()
Exemplo n.º 14
0
 def closeBrowsers(self):
     _log.info('Closing all existing chrome processes')
     chromes = NSRunningApplication.runningApplicationsWithBundleIdentifier_('com.google.Chrome')
     for chrome in chromes:
         chrome.terminate()
Exemplo n.º 15
0
 def bringWindowToForeground(self):
     if self.osType == "darwin":
         app = NSRunningApplication.runningApplicationWithProcessIdentifier_(
             self._getWindow()['kCGWindowOwnerPID'])
         app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
Exemplo n.º 16
0
	def activateWindow(self):
		app = NSRunningApplication.runningApplicationWithProcessIdentifier_(self.window[kCGWindowOwnerPID])
		app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)