I am using AppleScript and Python together to gather system information about the Macs in my stock as well as adding some supplemental info to the Spotlight comments field.
Specifically, AppleScript gathers the info on the Mac whose details I am capturing (whilst booted up to an external USB drive). I use dialogue boxes etc to gather feedback about OS version to be installed, the order number as well as the machine's actual marketing name (thanks to https://github.com/MagerValp/MacModelShelf), these are all saved as comments in the final System Profiler *.spx file that is generated/saved by the script.
I then use Dropbox to send the file back to my main Mac (which is running Filemaker). I use a rather complicated Python script to read the XML data of the system profiler file and to then paste the critical hardware info such as serial numbers, HD size and type etc into the relevant fields of the database.
I would like to parse the Spotlight comments of the spx file to get at the addition info e.g marketing name, Model Name and Order Number.
I try using (in Python script)
spotlightComments = 'mdls -raw -name kMDItemFinderComment ' + str(file_path)
to parse the comments. Even in Terminal as a standalone command this returns just a blank line, despite the comments being visible when I right click the spx file and go to 'Get Info'. N.B this is different from the "(null)" I used to get when using other Cloud services such as Sync.com which don't appear to carry-over file meta-data such as Spotlight comments.
If I open the edit the file's Spotlight comments and add just a single space " " character at the end of the string the command works - i.e I get back something like
iMac Late 2012 | 300001234 | 10.12
This can be further split up with the Python command
parts = spotlightComments.split('|')
Anyway back to AppleScript!
I've tried making a folder action to automatically append a single space/" " character to the end of a file's comments the moment something is added to the folder containing it, but nothing at all appears to happen.
Here is my script...
on adding folder items to this_folder after receiving added_items repeat with currentFile in added_items set TheComment to the comment of the currentFile set comment of the currentFile to TheComment & " " end repeat end adding folder items to
Even when I swap out the appended string to be something far more obvious there is still no change. I've also tried using Automator.app's 'wizard' for making folder actions as well as manually writing the script, storing it in "~/Library/Scripts/Folder Action Scripts" and then connecting the folder to the script using "Folder Actions Setup"
How can I append text to existing comments in Finder via automation?