Page 1 of 1
How to access the "comment" property of a file?
Posted: Sun Aug 21, 2016 1:19 pm
by sritcp
I need to access the "comment" field of a file from within LC.
(This is the field that is displayed when you hit Command-I to display the information panel of a file -- where you can type in descriptive information).
Is there a simple way to read in / write out to this file property?
I know very little about working with OS elements, so please provide an example.
Thank you for any help,
Sri
Re: How to access the "comment" property of a file?
Posted: Sun Aug 21, 2016 4:42 pm
by Klaus
Hi Sri,
you can use MDLS with SHELL to get these "Finder" infos.
For the comment use something like htis:
Code: Select all
on mouseUp
answer file "What Finder comment shall I display?"
put it into tFile
put shell("mdls -name kMDItemFinderComment" && QUOTE & tFile & QUOTE)
end mouseUp
Run this code and see what it will return.
Very easy to parse the result!
Try this to see what other infos the MDLS shell command can return about a file:
Code: Select all
on mouseUp
answer file "sdsdsd"
put it into tFile
put shell("mdls" && QUOTE & tFile & QUOTE)
end mouseUp
Best
Klaus
Re: How to access the "comment" property of a file?
Posted: Sun Aug 21, 2016 7:13 pm
by sritcp
Hi Klaus:
Thank you so much!
Your code worked (as it always does!).
Now, how would I save an edited "comment" back into the file data?
Thanks,
Sri
Re: How to access the "comment" property of a file?
Posted: Tue Aug 23, 2016 10:24 am
by [-hh]
Yet another option is to use applescript, works here (tested) in LC 6/7/8.
Code: Select all
-- Use Finder's "Get info" box in MacOS
-- Get and set "Comments" via applescript
on setComment fPath,fComment
do "tell application " & qq("Finder") &cr& \
"set fn to POSIX file " & qq(fPath) &cr& \
"set comment of (fn as alias) to " & qq(fComment) &cr& \
"end tell" as applescript
end setComment
function getComment fPath
do "tell application " & qq("Finder") &cr& \
"set fn to POSIX file " & qq(fPath) &cr& \
"set finfo to comment of (fn as alias)" &cr& \
"end tell" as applescript
return the result
end getComment
-- usage example
on mouseUp
answer file "Give me a path."
if it is empty then exit mouseUp
put it into fPath
-- use \n instead of cr
put (the internet date) & "\nThe matrix has you." into fComment
setComment fPath,fComment
put getComment(fPath) into rslt
put "FILE = " & qq(fPath) &cr& "COMMENT = " & rslt into fld "info"
end mouseUp
function qq strng
return quote&strng"e
end qq
Re: How to access the "comment" property of a file?
Posted: Thu Oct 06, 2016 8:11 pm
by sritcp
Thank you so much, Hermann!
I apologize for the delay in acknowledging your post.
I was out of circulation for a while.
Just today I was able to run your code and check it out. Just what I needed!
Regards,
Sri