Having seen many requests for scripts to mass remove tags, I thought I would share the following. However, it is responds to a particularly odd problem, so I’m not sure how widely useful it will be.
I had an unfortunate encounter with the program “Doo”, which automatically added a few hundred Open-Meta tags to my files, including a bunch of PDFs that I have indexed. Of course, DT converted the OM tags into its own tags, so my nice neat tagging system was polluted with these hundreds of junk tags. But, I couldn’t just remove all the tags, as the PDFs also had been tagged with non-junk tags I wanted to keep. Thus, the included code.
The user selected one or more tags and invokes the script. Each selected tag is then removed from EVERY record to which it has been applied. Other tags should not be affected, but I’m not promising anything. Thereafter, the user may delete the now empty tags if he or she wishes.
The basic mechanism I used is to move the replicants from each selected tag group to the trash, which is the same as removing the tag. One could use delete instead of moving to the trash, but I like the second chance created by a pause in the trash.
(*
Remove these tags - Removes a selected set of tags from ALL records so tagged. Should leave other tags alone.
Copyright © 2013, Glenn Hoetker <Glenn.Hoetker@asu.edu>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the
names of the contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
tell application "DEVONthink Pro"
activate
set selectedTags to the selection
if selectedTags is {} then error "Please select some tags."
repeat with thisTag in selectedTags
set theRecords to children of thisTag
repeat with theRecord in theRecords
move record theRecord from thisTag to the trash group of the database of theRecord
end repeat
end repeat
end tell
One lesson I learned is in the line
move record theRecord from thisTag to the trash group of the database of theRecord
The “from thisTag” part is critical. Otherwise, all copies of the record get trashed, which is NOT what we want.