Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Copy Finder Tags to Spreadsheet then copy back?

I have hundreds of files that have Finder Tags



Is there anyway to copy this data to a spreadsheet so it looks like this:


When I try to copy the files from the Finder it only puts in the file names in the spreadsheet and not the tags.


Also, if I manipulate the tags in the spreadsheet, is there anyway I can 'copy' the update tags back to Finder, e.g. so if in the spreadsheet, I change wetlands.txt tags to 'grade7, grade5, gradeA, grade9', then I can have this automatically update it in the Finder?


Thanks for any help that can be offered. I have not posted this question anywhere else.


Software I am using:

Mac OS 10.14.6 (18G87)

Numbers version 6.1 (6369)

MacBook Pro Retina

Posted on Sep 3, 2019 3:43 AM

Reply
Question marked as Best reply

Posted on Sep 4, 2019 9:44 AM

Here is the AppleScript/Objective-C script to be run in the Script Editor (or saved as an Application). Look at the property NumTbl as it will write a table directly into Numbers if set to true, or output to a CSV file if set to false. Right-click on the CSV (default tags.csv) and open in Numbers.


Copy/Paste the following into the Script Editor, click the compile button, and run.


This script is too long for the normal script posting <> facility, so it is in the following accordion:




Similar questions

14 replies
Question marked as Best reply

Sep 4, 2019 9:44 AM in response to big_smile

Here is the AppleScript/Objective-C script to be run in the Script Editor (or saved as an Application). Look at the property NumTbl as it will write a table directly into Numbers if set to true, or output to a CSV file if set to false. Right-click on the CSV (default tags.csv) and open in Numbers.


Copy/Paste the following into the Script Editor, click the compile button, and run.


This script is too long for the normal script posting <> facility, so it is in the following accordion:




Sep 3, 2019 4:43 AM in response to big_smile

It's not exactly what you're looking for. Anyway, NeoFinder and File List Export can export tables of files. The former seems to not separate the tags with a comma, though. The latter seems quite powerful.


The terminal command mdls shows, among other things, the tags. The problem is that you have to find a way to extract only that information. Moreover I don't know if it works on multiple files.

Sep 5, 2019 5:36 AM in response to Marco Klobas

Marco,


The following works for fonts, Photoshop layers, and tags. Probably more.


#!/usr/bin/awk -f
#
# trmdls.awk
# Usage: mdls -name kMDItemFonts filename | trmdls.awk

# 1) one line to process. Print entire third field
NR == 1 && !/\(/ {print substr($0, index($0,$3))}

# 2) multiple lines. Skip first and last lines containing '(' and ')'
#    Remove quotes and trailing ",". Remove leading/trailing whitespace,
NR > 2 {print l} {$1=$1}1 {gsub(/,$/, "");gsub(/"/, "");l=$0}
END {exit}


Sep 3, 2019 9:17 AM in response to big_smile

How are your files stored? One flat directory with all the files at that level, or is there a hierarchy of folders within that directory that need to be traversed? Are the files all text (.txt) files?


AppleScript can get files in a flat directory or can recursively get filenames from a folder hierarchy in the parent folder. I just need to know how you organized the first paragraph.


One must use AppleScript/Objective-C to extract the tag names from a given file, or update with tagname changes. I have an AppleScript/Objective-C scripting library that does this, so populating column 2 data for a file's tagnames is handled. The column 1 data will have to be full POSIX (UNIX) paths to the filenames, since the Objective-C routines expect this format. If you add new tag names in Numbers, then they must also be added to the Finder Preferences Tags panel with assigned (or no) color before they can be updated in the original file.


I already have an AppleScript that can construct a CSV file, so getting and appending the column data before writing the finished CSV file that you import into Numbers, should be relatively straight-forward. Getting the revised Number table data out and knowing which files need their tag names updated will be more complicated.







Sep 3, 2019 2:43 PM in response to rccharles

Neither of those approaches is for someone that may be imtimidated by Xcode, or the command-line.


As I mentioned earlier, I have an AppleScript/Objective-C script library that can be called from a normal AppleScript. It can set new tags, add, remove, or update with additional tag names.


use tagLib : script "Tag_cafe"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions

set tag_string to tagLib's tags_string(filepath)
log tag_string
(*Gray, Yellow, Broll*)



Sep 4, 2019 11:32 AM in response to VikingOSX

Wow, that's awesome and works perfectly. Thank you very much!!


At the risk of sounding greedy and ungrateful (which is not my intention) is it possible to 'copy' the update tags back to Finder, e.g. so if in the spreadsheet, I change wetlands.txt tags to 'grade7, grade5, gradeA, grade9', then I can have this automatically update it in the Finder? Googling around, I think this might not actually be possible, as I think Apple Script doesn't allow tags to be manipulated like that. If it's not possible, not to worry as this is already perfect enough! Thanks again so much for your help and all the time and effort you put into this! I greatly appreciate it :)

Sep 4, 2019 12:02 PM in response to big_smile

I understood what you wanted, and did not implement it due to additional complexity and time commitment.


Pure AppleScript, and particularly the Finder, is completely clueless about tag names, or how to read or set them. It can only assign the default colors as an integer label index. Programmatically, it cannot assign multiple colors to a given file either. To deal with tag names, one must do so by adding specialized Objective-C code to AppleScript.


The other challenge is that let's say you add additional tags to a cell entry. The Objective-C code will add a previously undefined tag to the target file, and it will appear as no color in the Finder Preferences : Tags panel. As soon as you assign a color to the new tag in that panel, it will appear on the file. [ Just tested that issue].


Then there is the Numbers code to extract the full pathname and updated tags. I would have to process all of them whether tag names were updated or not because I have no means to tell if additional tags have been added for specific files.


So, this would take alot of time that I do not have available.

Copy Finder Tags to Spreadsheet then copy back?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.