Friday, October 18, 2019

#1 2005-09-22 05:00:55 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Set Finder/Spotlight Comments

Applescript:

tell application "Finder"
   activate
   
   try
       set thisFolder to (target of front Finder window) as alias
   on error
       choose folder with prompt "Set comments of files in this folder:"
       set thisFolder to result
   end try
   
   display dialog "Comment:" default answer "" with title "Set Spotlight Comments"
   set newComment to text returned of result
   
   display dialog "How to handle existing comments?" buttons {"Overwrite", "Cancel", "Append"} default button 3 with title "Set Spotlight Comments"
   
   if (button returned of result) is "Overwrite" then
       set comment of every file of folder thisFolder to newComment
   else
       get every file of folder thisFolder
       repeat with thisFile in result
           tell thisFile
               if length of (comment as text) is not 0 then
                   get ", " & newComment
               else
                   get newComment
               end if
               set comment to (comment & result)
           end tell
       end repeat
   end if
   
   beep
end tell


Filed under: Finder

Offline

 

#2 2005-09-26 02:53:45 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Set Finder/Spotlight Comments

Added support for “selection”:

Applescript:

tell application "Finder"
   activate
   set fileList to selection
   
   if (count result) is 0 then
       try
           get (target of front Finder window) as alias
       on error
           choose folder with prompt "Set comments of files in this folder:"
       end try
       
       try
           set theFolder to result
           set fileList to every file of folder (result) as alias list
       end try
   end if
   
   display dialog "Comment:" default answer "" with title "Set Spotlight Comments"
   set newComment to text returned of result
   
   display dialog "How to handle existing comments?" buttons {"Overwrite", "Cancel", "Append"} default button 3 with title "Set Spotlight Comments"
   
   if (button returned of result) is "Overwrite" then
       if (class of first item of fileList) is alias then
           set comment of every file of folder theFolder to newComment
       else
           repeat with thisFile in fileList
               set comment of thisFile to newComment
           end repeat
       end if
   else
       repeat with thisFile in fileList
           tell thisFile
               if length of (comment as text) is not 0 then
                   get ", " & newComment
               else
                   get newComment
               end if
               set comment to (comment & result)
           end tell
       end repeat
   end if
   
   beep
end tell

Offline

 

#3 2008-05-23 10:15:35 am

MichaelZed
Member
Registered: 2008-05-23
Posts: 1

Re: Set Finder/Spotlight Comments

Streamlined the interface by combining two separate dialogues into one:

Applescript:

tell application "Finder"
   activate
   set fileList to selection
   
   if (count result) is 0 then
       try
           get (target of front Finder window) as alias
       on error
           choose folder with prompt "Set comments of files in this folder:"
       end try
       
       try
           set theFolder to result
           set fileList to every file of folder (result) as alias list
       end try
   end if
   
   display dialog "Comment:" default answer "" buttons {"Overwrite", "Cancel", "Append"} default button 3 with title "Set Spotlight Comments"
   
   set userInput to the result
   
   set newComment to text returned of userInput
   
   if (button returned of userInput) is "Overwrite" then
       if (class of first item of fileList) is alias then
           set comment of every file of folder theFolder to newComment
       else
           repeat with thisFile in fileList
               set comment of thisFile to newComment
           end repeat
       end if
   else
       repeat with thisFile in fileList
           tell thisFile
               if length of (comment as text) is not 0 then
                   get ", " & newComment
               else
                   get newComment
               end if
               set comment to (comment & result)
           end tell
       end repeat
   end if
   
end tell


Filed under: Finder

Offline

 

#4 2008-07-03 03:45:32 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Set Finder/Spotlight Comments

MichaelZed wrote:

Streamlined the interface by combining two separate dialogues into one:


I did this myself, but I forgot to repost it. Thanks!

Offline

 

#5 2008-11-25 06:32:22 am

Mark67
Member
Registered: 2005-12-22
Posts: 780

Re: Set Finder/Spotlight Comments

Bruce, Im thinking of marking up a lot of image files with a very similar script to yours. You don't happen to know if there is any length limit on the comment string? I wish to add keywords to files by using TID's on a folder hierarchy. I have not yet calculated how deep this will go.

Offline

 

#6 2009-02-28 11:33:37 am

panwudi
Member
From:: shanghai
Registered: 2009-02-28
Posts: 1
Website

Re: Set Finder/Spotlight Comments

It's a great script!
but if you save this script as an application packege, the default is itself, so you must deselect the script file when the script running prompt,and then select the files you want to comment. Need a little modifcation for the selection part.


Filed under: Spotlight, comment

Offline

 

#7 2009-04-12 09:53:35 am

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Set Finder/Spotlight Comments

panwudi wrote:

Need a little modifcation for the selection part.


I use the Script Menu for running most of my scripts…

Offline

 

#8 2009-08-19 07:33:11 am

Ptujec
Member
From:: Slovenia
Registered: 2009-01-17
Posts: 7
Website

Re: Set Finder/Spotlight Comments

I rewrote the script a bit to work also with Launchbar.
Actually I mixed it with another one I found here: http://forums.obdev.at/viewtopic.php?f=24&t=137&start=0

- You can select files with LaunchBar OR Finder.
- If no item is selected on run it will open a "Choose Dialog".
- You can see current tags of selected items ... even if you don't enter new tags.
- You could run the script also via e.g. the Script Menu ... though it depends on LaunchBar for "large type"

The only thing I couldn't get to work is Growl Notifications. I'm using LaunchBars "large type" feature instead for now. Any ideas?

Applescript:

-- »Tags« - Add Spotlight comments to your files and folders (with LaunchBar or Finder)!
-- by Ptujec 18-08-09
--
-- Sources:
-- [url]http://macscripter.net/viewtopic.php?pid=99577#p99577[/url]
-- [url]http://forums.obdev.at/viewtopic.php?t=137[/url]
----------------------------------

on run
   tell application "Finder"
       activate
       set itemList to selection
       
       if (count result) is 0 then
           tell me to activate
           choose file with multiple selections allowed without invisibles
           set itemList to result
       end if
       
   end tell
   
   tell me to activate
   tagging(itemList)
end run


on open (itemList)
   
   tell me to activate
   tagging(itemList)
end open

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

on tagging(itemList)
   
   display dialog "Comment:" default answer "" buttons {"Cancel", "Overwrite", "Append/Show"} default button 3 with title "Spotlight comments"
   set userInput to the result
   set newTags to text returned of userInput
   
   -- copy new Tags to clipboard
   if newTags is not "" then
       set the clipboard to newTags
   end if
   
   
   tell application "Finder"
       
       if (button returned of userInput) is "Overwrite" then
           
           repeat with this_item in itemList
               set item_name to (get displayed name of this_item)
               
               set comment of this_item to newTags
               
               if newTags is not "" then
                   -- If you don't use LaunchBar you can substitude the next tell section with:
                   -- display dialog "One or more items untagged!"
                   
                   tell application "LaunchBar"
                       display in large type "Item(s) tagged: " & "\n" & newTags as text
                   end tell
               else
                   tell application "LaunchBar"
                       display in large type "All items untagged!" as text
                   end tell
                   
               end if
           end repeat
       else
           
           repeat with this_item in itemList
               set item_name to (get displayed name of this_item)
               set current_com to (get comment of this_item)
               if current_com does not contain newTags then
                   if current_com is "" then
                       set comment of this_item to newTags
                       tell application "LaunchBar"
                           display in large type "Item(s) tagged: " & "\n" & newTags as text
                       end tell
                   else
                       set comment of this_item to (current_com & ", " & newTags) as string
                       tell application "LaunchBar"
                           display in large type "Item(s) tagged: " & "\n" & current_com & ", " & newTags as text
                       end tell
                       
                       
                   end if
               else
                   -- If you don't use LaunchBar you can substitude the next tell section with:
                   -- display dialog "One or more items already tagged: " & "»" & newTags & "«"
                   
                   tell application "LaunchBar"
                       display in large type "Item(s) already tagged: " & "\n" & current_com as text
                   end tell
                   
               end if
           end repeat
       end if
       
   end tell
   
   --- option autohide
   -- tell application "LaunchBar"
   --    delay 1.5
   --    hide
   -- end tell
   
end tagging

Offline

 

#9 2010-09-01 02:15:21 pm

danwan
Member
Registered: 2008-03-21
Posts: 210

Re: Set Finder/Spotlight Comments

I tried to set as comment the actual file name for each file in the chosen folder from your script however I am not skilled enough to modify it.
I need to do so to be able to edit when needed certain specific images from a Quicktime movie.

Is rather long and useless to expain why I need such thing. However it is the only way for me to solve some Editing problems in that movie.

Could you help and tell me how to modify the "insert a comment valid for all files in the folder through the dialog" to  a set the comment with each file name (not path) as performed from the script.

Thanks

Bruce Phillips wrote:

Applescript:

tell application "Finder"
   activate
   
   try
       set thisFolder to (target of front Finder window) as alias
   on error
       choose folder with prompt "Set comments of files in this folder:"
       set thisFolder to result
   end try
   
   display dialog "Comment:" default answer "" with title "Set Spotlight Comments"
   set newComment to text returned of result
   
   display dialog "How to handle existing comments?" buttons {"Overwrite", "Cancel", "Append"} default button 3 with title "Set Spotlight Comments"
   
   if (button returned of result) is "Overwrite" then
       set comment of every file of folder thisFolder to newComment
   else
       get every file of folder thisFolder
       repeat with thisFile in result
           tell thisFile
               if length of (comment as text) is not 0 then
                   get ", " & newComment
               else
                   get newComment
               end if
               set comment to (comment & result)
           end tell
       end repeat
   end if
   
   beep
end tell



Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)