Skip to content

Instantly share code, notes, and snippets.

@derickfay
Last active January 26, 2016 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derickfay/7205576 to your computer and use it in GitHub Desktop.
Save derickfay/7205576 to your computer and use it in GitHub Desktop.
Adds the Keywords from the current selection in BibDesk to all linked files as Mavericks tags.
set plistFront to "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array>"
set plistEnd to "</array></plist>"
(* By Derick Fay, 2013-10-28 *)
(* Thanks to http://mosx.tumblr.com/post/54049528297/convert-openmeta-to-os-x-mavericks-tags-with-this for getting me started *)
tell application "BibDesk"
-- without document, there is no selection, so nothing to do
if (count of documents) = 0 then
beep
display dialog "No documents found." buttons {"•"} default button 1 giving up after 3
end if
set thePublications to the selection of document 1
-- get the keywords
repeat with thePub in thePublications
set currentKeywords to get keywords of thePub
-- convert the keywords to a plist for use with xattr
set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {", "}}
set tagList to text items of currentKeywords
set AppleScript's text item delimiters to myTID
set plistTagString to ""
repeat with theTag in tagList
set plistTagString to plistTagString & "<string>" & theTag & "</string>"
end repeat
set plistTagString to plistFront & plistTagString & plistEnd
-- add the tags
set theFiles to POSIX path of linked files of thePub
repeat with f in theFiles
do shell script "xattr -w com.apple.metadata:_kMDItemUserTags '" & plistTagString & "' " & quoted form of f
end repeat
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment