Add File Path as Spotlight Comment to multiple files using Automator and AppleScript

Hello,


I would like to add the current directory path of files as a spotlight comment embedded into each one, so when I move them I know where they where originally.


I'm trying to use the script bellow:


on run {input, parameters}

tell application "Finder"


repeat with thisfile in input

set theComment to POSIX path of thisfile

set comment of (thisfile as alias) to theComment


return input

end tell


end run

I keep getting a sintax error: Expected "end", but found "end tell".

Could someone please help me?

MacBook Pro (Retina, 13-inch, Mid 2014), OS X El Capitan (10.11.5)

Posted on Jul 9, 2016 9:49 PM

Reply
6 replies

Jul 10, 2016 12:39 PM in response to davicosta99

In addition to closing the repeat loop, you might also consider pre-existing comments.


As written, your script replaces any existing comment with the file's path. What if the file already has a comment? Are you prepared/expecting to lose that?


This revision prepends the path to any existing comment:


repeat with thisfile in input

set theComment to (POSIX path of thisfile) & return & (get comment of (thisfile as alias))

set comment of (thisfile as alias) to theComment

end repeat

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Add File Path as Spotlight Comment to multiple files using Automator and AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.