I'm a gigantic newbie to Applescript and am trying to write (what I think would be) a pretty simple script for a workflow. Basicly, the standard "Set Spotlight Comments For Finder Items" function, but I want the comments that are already on the file to show up in the entry box. What it's supposed to look like here:
http://i271.photobucket.com/albums/jj149/open0source/Picture2-2.png
But with the actual filename replaced by a variable of the path of the file that is being opened/dropped-onto the workflow. Any guidance is greatly appreciated.
(Edit)
This seems to work for getting the comments from a dropped file into a dialog box:
on open droppedItem
set itemPath to POSIX path of droppedItem
set itemComments to do shell script "mdls -name kMDItemFinderComment " & itemPath
display dialog itemComments
end open
but I can't use it as the workflow's script (replacing "display dialog" with "return")
(Edit 2)
Ditched automator, got a bare-bones-version working
on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments
end tell
end open
(Sorry for wasting anyone's time)
I'll update one more time when the entire thing is done, in case someone would like the final script.
(Edit 3)
Done,
on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments buttons {"Cancel", "Write"} default button 2
set newComments to text returned of r
if button returned of r is "Write" then
set comment of theFile to newComments
else
set comment of theFile to currentComments
end if
end tell
end open
http://i271.photobucket.com/albums/jj149/open0source/Picture2-2.png
But with the actual filename replaced by a variable of the path of the file that is being opened/dropped-onto the workflow. Any guidance is greatly appreciated.
(Edit)
This seems to work for getting the comments from a dropped file into a dialog box:
on open droppedItem
set itemPath to POSIX path of droppedItem
set itemComments to do shell script "mdls -name kMDItemFinderComment " & itemPath
display dialog itemComments
end open
but I can't use it as the workflow's script (replacing "display dialog" with "return")
(Edit 2)
Ditched automator, got a bare-bones-version working
on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments
end tell
end open
(Sorry for wasting anyone's time)
I'll update one more time when the entire thing is done, in case someone would like the final script.
(Edit 3)
Done,
on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments buttons {"Cancel", "Write"} default button 2
set newComments to text returned of r
if button returned of r is "Write" then
set comment of theFile to newComments
else
set comment of theFile to currentComments
end if
end tell
end open