def processexistsforpath(path): """Does a local process launched from the specified application file exist? Note: if path is invalid, a MacOSError is raised. """ try: ae.psnforapplicationpath(path) return True except ae.MacOSError, err: if err.args[0] == -600: return False else: raise
def localapp(path, newinstance=False, hide=False): """Make an AEAddressDesc identifying a local application. (Application will be launched if not already running.) path : string -- full path to application, e.g. '/Applications/TextEdit.app' newinstance : bool -- launch a new application instance? hide : bool -- hide after launch? Result : AEAddressDesc """ # Always create AEAddressDesc by process serial number; that way there's no confusion if multiple versions of the same app are running if newinstance: desc = _launchapplication(path, _runevent, newinstance, hide) else: try: desc = ae.psnforapplicationpath(path) except ae.MacOSError, err: if err.args[0] == -600: # Application isn't running, so launch it in background and send it a standard 'run' event. sleep(1) desc = _launchapplication(path, _runevent, newinstance, hide) else: raise
def launchapp(path, newinstance=False, hide=False): """Send a 'launch' event to an application. If application is not already running, it will be launched in background first. path : string -- full path to application, e.g. '/Applications/TextEdit.app' newinstance : bool -- launch a new application instance? hide : bool -- hide after launch? Result : AEAddressDesc """ if newinstance: desc = _launchapplication(path, _launchevent, newinstance, hide) else: try: # If app is already running, calling ae.launchapplication will send a 'reopen' event, so need to check for this first: desc = ae.psnforapplicationpath(path) except ae.MacOSError, err: if err.args[0] == -600: # Application isn't running, so launch it and send it a 'launch' event: sleep(1) desc = _launchapplication(path, _launchevent, newinstance, hide) else: raise else: # App is already running, so send it a 'launch' event:
def localapp(path, newinstance=False, hide=False): """Make an AEAddressDesc identifying a local application. (Application will be launched if not already running.) path : string -- full path to application, e.g. '/Applications/TextEdit.app' newinstance : bool -- launch a new application instance? hide : bool -- hide after launch? Result : AEAddressDesc """ # Always create AEAddressDesc by process serial number; that way there's no confusion if multiple versions of the same app are running if newinstance: desc = _launchapplication(path, _runevent, newinstance, hide) else: try: desc = ae.psnforapplicationpath(path) except ae.MacOSError, err: if err.args[ 0] == -600: # Application isn't running, so launch it in background and send it a standard 'run' event. sleep(1) desc = _launchapplication(path, _runevent, newinstance, hide) else: raise
def launchapp(path, newinstance=False, hide=False): """Send a 'launch' event to an application. If application is not already running, it will be launched in background first. path : string -- full path to application, e.g. '/Applications/TextEdit.app' newinstance : bool -- launch a new application instance? hide : bool -- hide after launch? Result : AEAddressDesc """ if newinstance: desc = _launchapplication(path, _launchevent, newinstance, hide) else: try: # If app is already running, calling ae.launchapplication will send a 'reopen' event, so need to check for this first: desc = ae.psnforapplicationpath(path) except ae.MacOSError, err: if err.args[ 0] == -600: # Application isn't running, so launch it and send it a 'launch' event: sleep(1) desc = _launchapplication(path, _launchevent, newinstance, hide) else: raise else: # App is already running, so send it a 'launch' event: