I apologize if I have missed some obvious way to do this but how exactly do I add tags to several documents that are selected?
If I select, for example, four note documents that I have and wish to tag them all the same, I seem to enter the tags in the tag line at the bottom of the window or in the info window. In both places it just says, “Multiple Selection”
This makes sense since the documents could all have different tags, but is there a separate way to add tags to them all at the same time without writing an applescript?
If the documents in a selection do not have the same tags then a script is the way to go. This is the one I use. It’s simplistic - add one tag at a time. It could be improved to understand and parse delimited strings, etc.
-- select some records (discontiguous selections are OK)
-- add one tag at a time to the existing tags in those records
-- repeat as needed
-- use at your own risk: loss of data is your risk
tell application id "com.devon-technologies.thinkpro2"
try
set these_items to the selection
if these_items is {} then error "Please select some contents."
set thePrompt to "Enter One Tag to Append to All Tags..."
set theQuestion to display dialog thePrompt default answer ""
set theAppend to text returned of theQuestion
repeat with this_item in these_items
set the_tags to the tags of this_item
set newTags to the_tags & theAppend
set the tags of this_item to newTags
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
There are a couple of scripts available already, such as the one korm posted. If you don’t want to use a script, you can drag the documents to a tag group or groups to apply the tags. One of the quickest ways to do this is to display the Groups & Tags pane (Tools>Show Groups & Tags).
If the documents in a selection are all untagged, (or have the same tag(s)) then tags can be added via the Info pane or the tag bar.
Thanks again korm for that script which works wonderfully. I modified your script to accept a comma delimited list of tags:
-- select some records (discontiguous selections are OK)
-- add one tag at a time to the existing tags in those records
-- repeat as needed
-- use at your own risk: loss of data is your risk
--Thanks for this script by korm, modified by K. M. Lawson posted at: http://www.devon-technologies.com/scripts/userforum/viewtopic.php?f=3&t=11511&start=0
--Thanks to Julio @ http://macscripter.net/viewtopic.php?id=24473 for this:
on split(someText, delimiter)
set AppleScript's text item delimiters to delimiter
set someText to someText's text items
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
return someText
end split
--Thanks to Bruce Phillips for this, see http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
tell application id "com.devon-technologies.thinkpro2"
activate
try
set these_items to the selection
if these_items is {} then error "Please select some contents."
set thePrompt to "Enter one or more tags to append to all tags, separated by commas"
set theQuestion to display dialog thePrompt default answer ""
set theAppend to text returned of theQuestion
--Remove spaces after the commas if they are there:
set theAppend to my replaceText(", ", ",", theAppend)
repeat with this_item in these_items
--split the answer by comma:
set tagList to my split(theAppend, ",")
set the_tags to the tags of this_item
set newTags to the_tags & tagList
set the tags of this_item to newTags
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell