Add Comment to a file -- Desktop/Finder/PathFinder

I have been trying to figure out if it is possible to add a comment to a file that is selected on/in the Desktop, Finder, or Pathfinder. I would like to trigger a macro to ask for user input and apply it as a comment to the selected file or a selection of files. Can anyone give me a few suggestions if this is possible.

I do have the Path Finder » Set Tags of Selected Items to Red to build upon so I think with some modification this macro could be tweaked to accomplish what I want.

Better yet though is if it would check to see if the file was selected on the Desktop, Finder or PathFinder. Finder could be excluded as PathFinder is my file manager of choice.

Thanks for any help!

Hey Gregory,

You can’t do this directly with Path Finder – however you can get a list of items selected in Path Finder, turn them into aliases, and operate on them using the Finder.

This AppleScript will place the given comment in the Get-Info comment of every selected item in the Finder.

------------------------------------------------------------
set theComment to "Your commentary is unnecessary and irrelevant!"

tell application "Finder"
  set finderSelectionList to selection as alias list
  if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
  
  repeat with i in finderSelectionList
    set comment of i to theComment
  end repeat
  
end tell
------------------------------------------------------------

This AppleScript will place the given comment in the Get-Info comment of every selected item in Path Finder.

------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/12/20 16:10
# dMod: 2015/12/20 16:16 
# Appl: Path Finder & Finder
# Task: Add comments to selected items in Path Finder
# Tags: @Applescript, @Script, @Path_Finder, @Add, @Comments, @Selection
------------------------------------------------------------

set theComment to "Your commentary is unnecessary and irrelevant!"

tell application "Path Finder"
  set pfSelectionList to selection
  if pfSelectionList ≠ missing value then
    repeat with i in pfSelectionList
      set (contents of i) to POSIX path of (contents of i)
    end repeat
  else
    error "Nothing is selected in Path Finder!"
  end if
end tell

repeat with i in pfSelectionList
  set (contents of i) to alias POSIX file (contents of i)
end repeat

tell application "Finder"
  repeat with i in pfSelectionList
    set comment of i to theComment
  end repeat
end tell

------------------------------------------------------------

You can use a Prompt for User Input action to collect the text for the comment.

You can get the text from a Keyboard Maestro variable into AppleScript easily:

https://wiki.keyboardmaestro.com/AppleScript

-Chris

You can set a comment on a file using the Set File Attribute action.

Use the Prompt for User Input action to get the comment, and see the Working with the Finder Selection topic for working with the Finder's selection.

2 Likes

It is truly amazing the incredible breadth of features provided by KM. :astonished:

Thanks Chris and Peter, I have not had any time yet to put this together but will try over the holiday. These features are new to me so I will read/play so that I understand how variables are created and passed.

Cheers!

Thanks again for the help! I could not have done this without your suggestions and scripts.

This is what I have come up with for the Pathfinder portion of what I was trying to do.

Now i would like to add to this if possible. Is there any way to check and see if the file/files are selected on the Desktop or in PathFinder and branch to appropriate routine.

Any suggestions would be welcome......Greg

Hey Greg,

You mean the Finder or Path Finder?

The Desktop can be accessed from either one.

-Chris