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
How to access the "comment" property of a file?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: How to access the "comment" property of a file?
Hi Sri,
you can use MDLS with SHELL to get these "Finder" infos.
For the comment use something like htis:
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:
Best
Klaus
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
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
Klaus
Re: How to access the "comment" property of a file?
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
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
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to access the "comment" property of a file?
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
shiftLock happens
Re: How to access the "comment" property of a file?
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
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