How to support this blog?

To support this blog, you can hire me as an OmegaT consultant/trainer, or you can send translation and project management jobs my way.

Search the site:

Tag files that you selected in Zotero

This is my first “Zotero” thing. Arguably not very related to translation, but who knows. It’s an attempt at answering the following comment on the Zotero forum:

https://forums.zotero.org/discussion/comment/454302/#Comment_454302


Once you have used “Show in Finder” in the main Zotero window, all the selected items that have a local attachment will open in Finder in their own Zotero managed window. Now, if you want to add the same tag to each of them, you’ll have to apply the tag one by one to each window contents. Above 3 items, it’s not fun anymore.


This script checks that only the Zotero managed Finder windows are concerned by the tag change and apply the set tag (here “Zotero”) to the front window selection, close the window, etc. until the last window is closed.


Once you have done that, you can use Finder’s tag list to find all your newly tagged files. I even added a commented out line if you want to get the “mdfind” output of a search on that tag.




use AppleScript version "2.4" -- Yosemite (10.10) or later

use framework "Foundation"

use scripting additions


# use Shane Stanley's TAG library located here

# https://lists.apple.com/archives/applescript-users/2015/Jan/msg00193.html

# I’ve copied the code below, but you can put it in a script library and load it with a "use" statement as above


set myTag to "Zotero"


tell application "Finder"

set nbofWindows to number of Finder windows

repeat with myWIndow from 1 to nbofWindows

try

if name of container of target of front Finder window is "storage" then

(my setTags:{myTag} forPath:(POSIX path of (selection as alias)))

tell front Finder window to close

# the tag name here can be changed as you need

# or you can script a selection from an Applescript menu, etc.

end if

on error

tell front Finder window to close

end try

end repeat

end tell



# To get the list of files with that tag:

# set filePath to do shell script "mdfind -name 'kMDItemUserTags == \"" & myTag & "\"cdw'"



on returnTagsFor:posixPath -- get the tags

set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL

set {theResult, theTags} to aURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(missing value)

if theTags = missing value then return {} -- because when there are none, it returns missing value

return theTags as list

end returnTagsFor:


on setTags:tagList forPath:posixPath -- set the tags, replacing any existing tags

set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL

aURL's setResourceValue:tagList forKey:(current application's NSURLTagNamesKey) |error|:(missing value)

end setTags:forPath:


on addTags:tagList forPath:posixPath -- add to existing tags

set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL

-- get existing tags

set {theResult, theTags} to aURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(missing value)

if theTagsmissing value then -- add new tags

set tagList to (theTags as list) & tagList

set tagList to (current application's NSOrderedSet's orderedSetWithArray:tagList)'s allObjects() -- delete any duplicates

end if

aURL's setResourceValue:tagList forKey:(current application's NSURLTagNamesKey) |error|:(missing value)

end addTags:forPath:

Popular, if not outdated, posts...

.docx .NET .pptx .sdf .xlsx AASync accented letters Accessibility Accessibility Inspector Alan Kay alignment Apple AppleScript ApplescriptObjC AppleTrans applications Aquamacs Arabic archive Automator backup bash BBEdit Better Call Saul bug Butler C Calculator Calendar Chinese Cocoa Command line CSV CSVConverter database defaults Devon Dictionary DITA DocBook Dock Doxygen EDICT Emacs emacs lisp ergonomics Excel external disk file formats file system File2XLIFF4j Finder Fink Font français Free software FSF Fun Get A Mac git GNU GPL Guido Van Rossum Heartsome Homebrew HTML IceCat Illustrator InDesign input system ITS iWork Japanese Java Java Properties Viewer Java Web Start json keybindings keyboard Keynote killall launchd LISA lisp locale4j localisation MacPorts Mail markdown MARTIF to TBX Converter Maxprograms Mono MS Office NeoOffice Numbers OASIS Ocelot ODF Okapi OLPC OLT OmegaT OnMyCommand oo2po OOXML Open Solaris OpenDocument OpenOffice.org OpenWordFast org-mode OSX Pages PDF PDFPen PlainCalc PO Preview programming python QA Quick Look QuickSilver QuickTime Player Rainbow RAM reggy regular expressions review rsync RTFCleaner Safari Santa Claus scanner Script Debugger Script Editor scripting scripting additions sdf2txt security Services shell shortcuts Skim sleep Smultron Snow Leopard Spaces Spanish spellchecking Spotlight SRX standards StarOffice Stingray Study SubEthaEdit Swordfish System Events System Preferences Tags TBX TBXMaker Terminal text editing TextEdit TextMate TextWrangler The Tool Kit Time Capsule Time Machine tmutil TMX TMX Editor TMXValidator transifex Translate Toolkit translation Transmug troubleshooting TS TTX TXML UI Browser UI scripting Unix VBA vi Virtaal VirtualBox VLC W3C WebKit WHATWG Windows Wine Word WordFast wordpress writing Xcode XLIFF xml XO xslt YAML ZFS Zip Zotero