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.
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:
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.
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.
I found this Script which does nearly what I need it to do. As I do have no programming skills I'm asking If someone could help me modify the script (pathfinder part of it) to append to the comments if there are already comments in the file.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/12/20 16:10
# dMod: 2021/10/14 10:18
# Appl: Path Finder & Finder
# Task: Add comments to selected items in Path Finder
# : Append new comment if there is an existing comment.
# Tags: @Applescript, @Script, @Path_Finder, @Add, @Comments, @Selection
--------------------------------------------------------
set newComment to "Your commentary is unnecessary and irrelevant!"
tell application "Path Finder"
set pfSelectionList to selection
if pfSelectionList ≠ missing value then
repeat with selectedItem in pfSelectionList
set (contents of selectedItem) to POSIX path of (contents of selectedItem)
end repeat
else
error "Nothing is selected in Path Finder!"
end if
end tell
repeat with selectedItem in pfSelectionList
set (contents of selectedItem) to alias POSIX file (contents of selectedItem)
end repeat
tell application "Finder"
repeat with theItem in pfSelectionList
set oldItemComment to theItem's comment
if oldItemComment ≠ "" then
set newComment to oldItemComment & space & newComment
set theItem's comment to newComment
else
set theItem's comment to newComment
end if
end repeat
end tell
--------------------------------------------------------
Hi @ccstone,
Is possible to write the comment and not use the one on the code with a dialog box or other. With this I can write different comments per file.
The script is deliberately designed to add your comment to anything already there:
set oldItemComment to theItem's comment
if oldItemComment ≠ "" then
set newComment to oldItemComment & space & newComment
set theItem's comment to newComment
else
set theItem's comment to newComment
end if
Save the current comment if there is one
If item already has a comment, add the new comment to the end of the old then apply it all to the item
If it doesn't, apply just the new comment to the item
If you want to overwrite any/all comments with your new one then try changing the repeat loop to:
repeat with theItem in pfSelectionList
set theItem's comment to newComment
end repeat
As @Nige_S has just written, the last version of the AppleScript is designed to append the new comment rather than replace it. There are earlier versions in Post #2 that replace the comments.
The following script works perfectly for me to replace comment:
set newComment to the text returned of (display dialog "Please type a comment" default answer "")
set theComment to ""
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
tell application "Finder"
repeat with i in pfSelectionList
set comment of i to theComment
end repeat
end tell
tell application "Finder"
repeat with theItem in pfSelectionList
set oldItemComment to theItem's comment
if oldItemComment ≠ "" then
set newComment to oldItemComment & space & newComment
set theItem's comment to newComment
else
set theItem's comment to newComment
end if
end repeat
end tell