Created
March 8, 2019 01:30
-
-
Save chrisgrande/b5d05239d36dcf1015e94bac155047d4 to your computer and use it in GitHub Desktop.
Check if app is running, if not, launch it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from AppKit import NSWorkspace, NSBundle, NSRunningApplication | |
import sys | |
# app to look for and launch if not running | |
app_name = 'OneDrive' | |
app_bundle_id = 'com.microsoft.OneDrive' | |
# hide the python rocket ship | |
bundle = NSBundle.mainBundle() | |
info = bundle.localizedInfoDictionary() or bundle.infoDictionary() | |
info['LSUIElement'] = '1' | |
# get the shared workspace object | |
workspace = NSWorkspace.sharedWorkspace() | |
# check if app is running - if not - launch it | |
if NSRunningApplication.runningApplicationsWithBundleIdentifier_(app_bundle_id): | |
print('%s is Running!' % app_name) | |
sys.exit(0) | |
else: | |
print('%s is NOT running... launching...' % app_name) | |
workspace.launchApplication_(app_name) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment