davicosta99

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

Close

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

  • All replies
  • Helpful answers

  • by Pierre L.,Solvedanswer

    Pierre L. Pierre L. Jul 10, 2016 6:47 AM in response to davicosta99
    Level 5 (4,484 points)
    Jul 10, 2016 6:47 AM in response to davicosta99

    You just forgot the “end repeat”:

              repeat with thisfile in input

                     set theComment to POSIX path of thisfile

                     set comment of (thisfile as alias) to theComment

               end repeat

  • by VikingOSX,Helpful

    VikingOSX VikingOSX Jul 10, 2016 6:47 AM in response to davicosta99
    Level 7 (20,819 points)
    Mac OS X
    Jul 10, 2016 6:47 AM in response to davicosta99

    In Spotlight (or Finder search) you would use comment:string, where string could be a folder in a given POSIX path. Thus, if  the file had originally been on your Desktop, you would use comment:Desktop to show the file(s) bearing that POSIX path in their comment field.

  • by davicosta99,

    davicosta99 davicosta99 Jul 10, 2016 6:52 AM in response to Pierre L.
    Level 1 (4 points)
    Mac OS X
    Jul 10, 2016 6:52 AM in response to Pierre L.

    Thank you very much, Pierre.

  • by Pierre L.,

    Pierre L. Pierre L. Jul 10, 2016 7:06 AM in response to davicosta99
    Level 5 (4,484 points)
    Jul 10, 2016 7:06 AM in response to davicosta99

    My pleasure.

  • by Camelot,

    Camelot Camelot Jul 10, 2016 12:39 PM in response to davicosta99
    Level 8 (47,285 points)
    Mac OS X
    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



  • by davicosta99,

    davicosta99 davicosta99 Jul 10, 2016 12:49 PM in response to Camelot
    Level 1 (4 points)
    Mac OS X
    Jul 10, 2016 12:49 PM in response to Camelot

    The files I wanted to apply this script to didn't have any comments previously, but I will consider your sugestion if I need to apply it to any future use case cenario. Thank you!