how get text from txt file into other file´s spotlight commentary?

hey there,

I am not a coder/scripter. thus I am looking for some initial help/clues to solve the problem sketched in the header.

I basically have a file-structure:

[folder :] …/xyxyxyxy.info

[file-1 :]…/xyxyxyxy.info/ababab.png [alternative extensions: .jpg, .tif]

[file-2 :]…/xyxyxyxy.info/metadata.json

what I need to achieve somehow:
scrptes/automated process to copy content of file-2 into spotlight-comments of file-1.

as said I am not a code-savvy person. my hunch is I can achieve this somehow on OSX with apple-script, automator, Hazel, folderscripts – or a combination of them. but really I need some starting help (at least).

I found some script suggestions here for copying text from a text-document to it´s own spotlight commentary field. but as one can see for me this copying would need to happen between a txt/json-file and another (image-)file located in same folder.

thankful to anyone who knows these realms, or possibly even has a solution (script) that can be used/adapted for this.

thx + best, oliver

You have no direct control over what Spotlight records – I suspect you’re thinking of the Finder’s comment property for items, which is what appears as the comment in Finder’s Get Info dialogs.

hey Shane,

… yes - that´s right. I was referring to Finder comments, expecting that (normally) they are picked up in Spotlight-index, and in other applications searches (– which is even more relevant for my use-case).

thanks for that correction, adding more precision.

This should get you started:

set picFile to (choose file)
set picPath to picFile as text
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {":"}}
set metaPath to (text 1 thru text item -2 of picPath) & ":metadata.json"
set AppleScript's text item delimiters to saveTID

set theData to read (metaPath as «class furl») as «class utf8»
tell application id "com.apple.finder" -- Finder
	set comment of picFile to theData
end tell

hello Shane,

thanks a load! this is enormous + enormously helpful.

I will dive into that, to try it out but also to try to comprehend/learn this stuff. (though I have to admit, I a not sure I will really get to the base of this, looking at your piece :slight_smile: ).

one thing, if I may ask, as it seems like one of those cliffhangers for the uninitiated (me) that knowledgeble people (you + other script-pros) can clear out in a sec:

set picFile to (choose file)
seems to be the one line that takes a variable here. as I said, I am still musing/hovering whether to get a grip on this via AppleScript alone, or with some help of Hazel, Folder Actions or other leveraging tools (using AppleScripts). – can you (or someone) hint, how I would treat this line, i.e. give the specification in some open/iterative batch process?
– or maybe the question is wrong/stupid, and I might learn on another front :slight_smile:

thx anyways for that massive starting assistance!
and I do hope the follow-up question doesn´t appear as ravenous…

will try this out either way, when I have some good headspace for these (to me) foreign terrains… :slight_smile:

best again! o