I don't know how this would translate to Launchbar but I have attached the underlying code and workflow below.
The overview of the workflow is:
The first step is a script filter that sends stdout to some bash scripts. The code for the script filter is:
Code: Select all
--------------------------------------------------------------------
-- SCRIPT FOR EXTRACTING REFERENCES FROM BOOKENDS
--------------------------------------------------------------------
on run argv
set query to argv as text
tell application "Bookends"
-- Extract UUID from Bookends
set AppleScript's text item delimiters to {return}
set refList to text items of («event ToySSQLS» "authors REGEX '" & query & "'")
set AppleScript's text item delimiters to {","}
set xml to "<?xml version=\"1.0\"?>" & linefeed
set xml to xml & "<items>" & linefeed
repeat with refItem in refList
set refItem to contents of refItem
-- Extract first Author
set refAuthorList to («event ToySRFLD» refItem given string:"authors")
set AppleScript's text item delimiters to {","}
set refAuthors to text items of refAuthorList
set AppleScript's text item delimiters to {"'"}
set refAuthor to first item of refAuthors
set AppleScript's text item delimiters to {""}
-- Extract and clean title to HTML friendly title
set refTitle to («event ToySRFLD» refItem given string:"title")
set findChars to {"&", "\"", "'", "<", ">"}
set replaceChars to {"&", """, "'", "<", ">"}
repeat with i from 1 to 5
if (item i of findChars) is in refTitle then
set AppleScript's text item delimiters to {item i of findChars}
set refTitle to text items of refTitle
set AppleScript's text item delimiters to {item i of replaceChars}
set refTitle to refTitle as text
set AppleScript's text item delimiters to {""}
end if
end repeat
-- Extract date
set refDateList to («event ToySRFLD» refItem given string:"thedate")
set regexDef to "([12][0-9][0-9][0-9])"
set refDate to (do shell script "if [[ \"" & refDateList & "\" =~ " & regexDef & " ]]
then echo \"${BASH_REMATCH[1]}\"
fi")
-- XML formatting
-- Set XML header
set xml to xml & linefeed & "<item uid=\"" & refItem & "\" arg=\"" & refItem & "\" valid=\"yes\">" & linefeed
set xml to xml & "<title>"
set xml to xml & refAuthor & " " & refDate
set xml to xml & "</title>" & linefeed
set xml to xml & "<subtitle>"
set xml to xml & refTitle
set xml to xml & "</subtitle>" & linefeed
set xml to xml & "<icon>file.png</icon>" & linefeed
set xml to xml & "</item>" & linefeed
end repeat
return xml
end tell
end run
The first script following from the script filter copies the citation to the clipboard in {Author Date UUID} format
Code: Select all
-------------------------------------------------------------------------
-- SCRIPT FOR SETTING CITATION USING {AUTHOR, DATE #UID}
-------------------------------------------------------------------------
on run argv
set refItem to argv as text
tell application "Bookends"
-- Extract first Author
set refAuthorList to («event ToySRFLD» refItem given string:"authors")
set AppleScript's text item delimiters to {","}
set refAuthors to text items of refAuthorList
set AppleScript's text item delimiters to {"'"}
set refAuthor to first item of refAuthors
set AppleScript's text item delimiters to {""}
-- Extract date
set refDateList to («event ToySRFLD» refItem given string:"thedate")
set regexDef to "([12][0-9][0-9][0-9])"
set refDate to (do shell script "if [[ \"" & refDateList & "\" =~ " & regexDef & " ]]
then echo \"${BASH_REMATCH[1]}\"
fi")
-- Set citation
set refCitation to "{" & refAuthor & ", " & refDate & ", #" & refItem & "}"
set the clipboard to {Unicode text:refCitation}
-- return refCitation
end tell
end run
The second bash script, accessed by the 'command' key copies a MultiMarkdown formatted citation to the clipboard
Code: Select all
UUID="{query}"
BIBKEY=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySRFLD» "$UUID" given string:"user1"
end tell
EOT)
echo "[#$BIBKEY]" | tr -d '\n'
The third bash script, accessed by the 'option' key copies a Pandoc formatted citation to the clipboard
Code: Select all
UUID="{query}"
BIBKEY=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySRFLD» "$UUID" given string:"user1"
end tell
EOT)
echo "@$BIBKEY" | tr -d '\n'
The fourth bash script (not in the Alfred script that I have posted and accessed through the 'control' key) opens a DevonThink pdf that is linked to Bookends by a URL that I keep in 'user4'
Code: Select all
UUID="{query}"
BIBKEY=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySRFLD» "$UUID" given string:"user4"
end tell
EOT)
open $BIBKEY
In the workflow there is a second script filter. This is the same as the first script filter but just accessed through a separate Alfred shortcut. It sends stdout to two bash scripts. The first copies a formatted bibliography to the clipboard:
Code: Select all
UUID="{query}"
REFNAME=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySGUID» "$UUID" given «class RRTF»:"true"
end tell
EOT)
echo "$REFNAME" | pbcopy
The second bash script accessed through the 'command' key (copies a MultiMarkdown formatted bibliography (Using the Vancouver style) to the clipboard as in [Reference]: bibliography
Code: Select all
UUID="{query}"
BIBKEY=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySRFLD» "$UUID" given string:"user1"
end tell
EOT)
REFNAME=$(/usr/bin/osascript << EOT
tell application "Bookends"
return «event ToySGUID» "$UUID" given «class RRTF»:"false", string:"Vancouver"
end tell
EOT)
echo "[#$BIBKEY]: $REFNAME"
Hope this helps. As I said I have no idea how Launch bar works but you might be able to reconfigure it for your use