diff --git a/services/Zotero: Cite in text editor of your choice.workflow/Contents/Info.plist b/services/Zotero: Cite in text editor of your choice.workflow/Contents/Info.plist new file mode 100644 index 0000000..9b37e23 --- /dev/null +++ b/services/Zotero: Cite in text editor of your choice.workflow/Contents/Info.plist @@ -0,0 +1,22 @@ + + + + + NSServices + + + NSBackgroundColorName + background + NSIconName + NSTouchBarShare + NSMenuItem + + default + Zotero: Cite in text editor of your choice + + NSMessage + runWorkflowAsService + + + + diff --git a/services/Zotero: Cite in text editor of your choice.workflow/Contents/QuickLook/Thumbnail.png b/services/Zotero: Cite in text editor of your choice.workflow/Contents/QuickLook/Thumbnail.png new file mode 100644 index 0000000..07aad8a Binary files /dev/null and b/services/Zotero: Cite in text editor of your choice.workflow/Contents/QuickLook/Thumbnail.png differ diff --git a/services/Zotero: Cite in text editor of your choice.workflow/Contents/document.wflow b/services/Zotero: Cite in text editor of your choice.workflow/Contents/document.wflow new file mode 100644 index 0000000..a800691 --- /dev/null +++ b/services/Zotero: Cite in text editor of your choice.workflow/Contents/document.wflow @@ -0,0 +1,152 @@ + + + + + AMApplicationBuild + 444.42 + AMApplicationVersion + 2.9 + AMDocumentVersion + 2 + actions + + + action + + AMAccepts + + Container + List + Optional + + Types + + com.apple.applescript.object + + + AMActionVersion + 1.0.2 + AMApplication + + Automator + + AMParameterProperties + + source + + + AMProvides + + Container + List + Types + + com.apple.applescript.object + + + ActionBundlePath + /System/Library/Automator/Run AppleScript.action + ActionName + Run AppleScript + ActionParameters + + source + (* This script allows to cite references from Zotero in various text editors. It relies on Better BibTeX for formatting the output *) (* It supports a number of output formats: + - Pandoc: to use with Pandoc and citeproc, formatted as [@Citation Key] + - Multimarkdon: + - Scannable Cite: + *) (* The reference is copied to the clipboard and pasted into the selected text editor *) (* To do: + - try to cite the reference already selected in Zotero +*) -- activeEditorsList will be populated in the course of the script's execution set activeEditorsList to {} -- set a list of text editors whose running status is to be checked. The order can be set to one's own preferences set editorsList to {"Scrivener", "Sublime Text", "Microsoft Word", "TextEdit", "nvALT"} -- set a list of output formats set formatsList to {"Pandoc", "MMD", "Scannable cite"} -- test if Zotero is running set zotRunning to do shell script "/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?probe=probe' 2>/dev/null; exit 0" if zotRunning is "" then display alert "Zotero not running" message "This script will not work unless Zotero is running. Please launch Zotero and try again" tell application appName activate end tell error number -128 -- test if Better BibTeX is instelled else if zotRunning is "No endpoint found" then display alert "Better BibTeX not installed" message "This script will not work unless Better BibTeX is installed. Please make sure that Better BibTeX is installed in the running instance of Zotero" tell application appName activate end tell error number -128 end if -- variable with running apps tell application "System Events" set activeProcesses to (name of every process) end tell -- variable with front most process tell application "System Events" set frontApp to (the name of every process whose frontmost is true) as string end tell -- variable with list of running text editors repeat with appName in editorsList if appName is in activeProcesses then set activeEditor to appName set end of activeEditorsList to appName end if end repeat -- ask user to select from running text editors if they front most app is not part of a list of text editors and if there are more then one. Otherwiese continue with the sole running text editor or abort the script set editorCount to (count activeEditorsList) -- the frontmost app is a text editor if frontApp is in editorsList then set targetApp to frontApp -- there is only one text editor running else if editorCount = 1 then set targetApp to (item 1 of activeEditorsList) as text -- there are multiple running text editors else if editorCount > 0 then set targetApp to (choose from list activeEditorsList with title "Running text editors" with prompt "Pick a text editor to send the reference's CitationID to" default items (item 1 of activeEditorsList) without multiple selections allowed) as text else -- Handle 0 items -- set error set alertTitle to "Error" set alertMessage to "There are no running text editors" -- display error message display alert alertTitle message alertMessage set targetApp to "false" end if -- ask user to select an output format set targetFormat to (choose from list formatsList with title "Available output formats" with prompt "Pick an output format for the citation tag" default items (item 1 of formatsList) without multiple selections allowed) as text -- test if Zotero is running set zotRunning to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?probe=probe' 2>/dev/null; exit 0" if zotRunning is "ready" then if targetFormat is "Pandoc" then set theReference to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?format=pandoc' 2>/dev/null; exit 0" set theTag to "[" & theReference & "]" else if targetFormat is "MMD" then set theReference to do shell script "/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=mmd' 2>/dev/null; exit 0" set theTag to theReference else if targetFormat is "Scannable cite" then set theReference to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?format=scannable-cite' 2>/dev/null; exit 0" set theTag to theReference else -- display error message display alert "Unknown output format" message "Better BibTeX does not return the selected target format" end if end if -- copy the citatin tag to the clipboard set the clipboard to theTag --as text -- debugging -- display dialog (the clipboard) -- paste the reference and page number into the selected text editor if targetApp is not "false" then tell application targetApp activate tell application "System Events" keystroke "v" using command down end tell end tell end if + + BundleIdentifier + com.apple.Automator.RunScript + CFBundleVersion + 1.0.2 + CanShowSelectedItemsWhenRun + + CanShowWhenRun + + Category + + AMCategoryUtilities + + Class Name + RunScriptAction + InputUUID + 27947C77-EB32-4AA9-A1F1-A2162203830E + Keywords + + Run + + OutputUUID + E7935E78-D442-4D28-BD7D-90D2F980A83B + UUID + 452789F2-4EE5-46B2-888C-89C855ADE9C4 + UnlocalizedApplications + + Automator + + arguments + + 0 + + default value + on run {input, parameters} + + (* Your script goes here *) + + return input +end run + name + source + required + 0 + type + 0 + uuid + 0 + + + isViewVisible + + location + 669.000000:368.000000 + nibPath + /System/Library/Automator/Run AppleScript.action/Contents/Resources/Base.lproj/main.nib + + isViewVisible + + + + connectors + + workflowMetaData + + applicationBundleIDsByPath + + applicationPaths + + inputTypeIdentifier + com.apple.Automator.nothing + outputTypeIdentifier + com.apple.Automator.nothing + presentationMode + 11 + processesInput + 0 + serviceInputTypeIdentifier + com.apple.Automator.nothing + serviceOutputTypeIdentifier + com.apple.Automator.nothing + serviceProcessesInput + 0 + systemImageName + NSTouchBarShare + useAutomaticInputType + 0 + workflowTypeIdentifier + com.apple.Automator.servicesMenu + + + diff --git a/zotpick.scpt b/zotpick.scpt new file mode 100644 index 0000000..eb86e90 Binary files /dev/null and b/zotpick.scpt differ