Пример #1
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()
Пример #2
0
 def bringWindowToForeground(self):
     if self.osType == "darwin":
         app = NSRunningApplication.runningApplicationWithProcessIdentifier_(
             self._getWindow()['kCGWindowOwnerPID'])
         app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
Пример #3
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)
	
Пример #4
0
	def activateWindow(self):
		app = NSRunningApplication.runningApplicationWithProcessIdentifier_(self.window[kCGWindowOwnerPID])
		app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)