def open_item(self): """Open item in Zotero client""" if self.zotquery.zotero_app == 'Standalone': app_id = 'org.zotero.zotero' elif self.zotquery.zotero_app == 'Firefox': app_id = 'org.mozilla.firefox' else: msg = 'Invalid app name: {}'.format(self.zotquery.zotero_app) raise ValueError(msg) scpt_str = """ if application id "{1}" is not running then tell application id "{1}" activate delay 0.5 activate delay 0.5 open location "zotero://select/items/" & "{0}" end tell else tell application id "{1}" activate delay 0.5 open location "zotero://select/items/" & "{0}" end tell end if """.format(self.arg, app_id) return utils.run_applescript(scpt_str)
def open_item(arg): """Open item in Zotero client""" if zq.backend.zotero_app == 'Standalone': app_id = 'org.zotero.zotero' elif zq.backend.zotero_app == 'Firefox': app_id = 'org.mozilla.firefox' else: msg = 'Invalid app name: {}'.format(zq.backend.zotero_app) raise ValueError(msg) scpt_str = """ set appName to name of application id "{app}" set startIt to false tell application "System Events" if not (exists process appName) then set startIt to true end if end tell if startIt then tell application appName open location "zotero://select/items/" & "{id}" set window_ids to id of every window whose id is not equal to -1 if window_ids is not equal to {{}} then my set_frontmost("Zotero") open location "zotero://select/items/" & "{id}" else activate my set_frontmost("Zotero") delay 1 open location "zotero://select/items/" & "{id}" delay 0.5 open location "zotero://select/items/" & "{id}" end if end tell else set_frontmost(appName) tell application appName to open location "zotero://select/items/" & "{id}" end if on set_frontmost(app_name) tell application "System Events" repeat while frontmost of process app_name is false set frontmost of process app_name to true end repeat end tell end set_frontmost """.format(id=arg, app=app_id) return utils.run_applescript(scpt_str)