Skip to content

Unified script #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSServices</key>
<array>
<dict>
<key>NSBackgroundColorName</key>
<string>background</string>
<key>NSIconName</key>
<string>NSTouchBarShare</string>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Zotero: Cite in text editor of your choice</string>
</dict>
<key>NSMessage</key>
<string>runWorkflowAsService</string>
</dict>
</array>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMApplicationBuild</key>
<string>444.42</string>
<key>AMApplicationVersion</key>
<string>2.9</string>
<key>AMDocumentVersion</key>
<string>2</string>
<key>actions</key>
<array>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.applescript.object</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>1.0.2</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.applescript.object</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run AppleScript.action</string>
<key>ActionName</key>
<string>Run AppleScript</string>
<key>ActionParameters</key>
<dict>
<key>source</key>
<string>(* 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 executionset activeEditorsList to {}-- set a list of text editors whose running status is to be checked. The order can be set to one's own preferencesset editorsList to {"Scrivener", "Sublime Text", "Microsoft Word", "TextEdit", "nvALT"}-- set a list of output formatsset formatsList to {"Pandoc", "MMD", "Scannable cite"}-- test if Zotero is runningset zotRunning to do shell script "/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?probe=probe' 2&gt;/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 instelledelse 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 -128end if-- variable with running appstell application "System Events" set activeProcesses to (name of every process)end tell-- variable with front most processtell application "System Events" set frontApp to (the name of every process whose frontmost is true) as stringend 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 ifend 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 scriptset editorCount to (count activeEditorsList)-- the frontmost app is a text editorif frontApp is in editorsList then set targetApp to frontApp -- there is only one text editor runningelse if editorCount = 1 then set targetApp to (item 1 of activeEditorsList) as text -- there are multiple running text editorselse if editorCount &gt; 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 textelse -- 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 formatset 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 runningset zotRunning to do shell script "/usr/bin/curl 'http://127.0.0.1:23119/better-bibtex/cayw?probe=probe' 2&gt;/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&gt;/dev/null; exit 0" set theTag to "[" &amp; theReference &amp; "]" else if targetFormat is "MMD" then set theReference to do shell script "/usr/bin/curl 'http://localhost:23119/better-bibtex/cayw?format=mmd' 2&gt;/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&gt;/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 ifend if-- copy the citatin tag to the clipboardset the clipboard to theTag --as text-- debugging-- display dialog (the clipboard)-- paste the reference and page number into the selected text editorif targetApp is not "false" then tell application targetApp activate tell application "System Events" keystroke "v" using command down end tell end tellend if</string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.Automator.RunScript</string>
<key>CFBundleVersion</key>
<string>1.0.2</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunScriptAction</string>
<key>InputUUID</key>
<string>27947C77-EB32-4AA9-A1F1-A2162203830E</string>
<key>Keywords</key>
<array>
<string>Run</string>
</array>
<key>OutputUUID</key>
<string>E7935E78-D442-4D28-BD7D-90D2F980A83B</string>
<key>UUID</key>
<string>452789F2-4EE5-46B2-888C-89C855ADE9C4</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<string>on run {input, parameters}

(* Your script goes here *)

return input
end run</string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
</dict>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>669.000000:368.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run AppleScript.action/Contents/Resources/Base.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
</array>
<key>connectors</key>
<dict/>
<key>workflowMetaData</key>
<dict>
<key>applicationBundleIDsByPath</key>
<dict/>
<key>applicationPaths</key>
<array/>
<key>inputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>outputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>presentationMode</key>
<integer>11</integer>
<key>processesInput</key>
<integer>0</integer>
<key>serviceInputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>serviceOutputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>serviceProcessesInput</key>
<integer>0</integer>
<key>systemImageName</key>
<string>NSTouchBarShare</string>
<key>useAutomaticInputType</key>
<integer>0</integer>
<key>workflowTypeIdentifier</key>
<string>com.apple.Automator.servicesMenu</string>
</dict>
</dict>
</plist>
Expand Down
Binary file added zotpick.scpt
Binary file not shown.