Sunday, June 16, 2019

#1 2019-04-15 11:41:43 am

leroyB
Member
Registered: 2019-04-15
Posts: 3

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

Offline

 

#2 2019-04-15 07:02:52 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5698

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

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-04-16 05:50:40 pm

leroyB
Member
Registered: 2019-04-15
Posts: 3

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

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.

Offline

 

#4 2019-04-16 06:33:32 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5698

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

This should get you started:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2019-04-17 05:20:09 am

leroyB
Member
Registered: 2019-04-15
Posts: 3

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

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 :-) ).

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 :-)

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... :-)

best again! o

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)