Page 1 of 4

Adding spotlight tags?

Posted: Wed Dec 13, 2006 12:11 pm
by macsterdam
Is it possible, or will ik be possible to add Spotlight tags to files/folders via LB?

Re: Adding spotlight tags?

Posted: Sun Dec 31, 2006 9:11 am
by FredB
macsterdam wrote:Is it possible, or will ik be possible to add Spotlight tags to files/folders via LB?


You can do it with AppleScript. Here is mine, it needs Growl and there are some specific stuff in it (name of the script, etc.). I could make a more generic one, but not today (Some kind of party ;).

You can find the script here

You need Growl or you should remove it from the script.
Paste the text in Script Editor, save the script as SpotlightCommenter.scpt somewhere. Select the files you want to tag, invoke the script in LB and hit cmd + D.

Posted: Sun Dec 31, 2006 8:02 pm
by SpiralOcean
Thanks for posting this Fred!

Posted: Mon Jan 08, 2007 1:59 pm
by macsterdam
Thanks very much indeed - haven't tried it yet, but will shortly! Much appreciated!

FredB - thanks much.

Posted: Sun Jul 22, 2007 8:49 am
by friedmandesigns
Fred, script is perfect. many thanks. :)

addition for "Nonactivating Mode"

Posted: Sun Jan 11, 2009 7:45 pm
by ptujec
I added a line in the code to make it work if you run LB in "Nonactivating Mode". Plus I thought its cooler if Growl shows the Spotlight Icon in the Notification.

Enjoy!

Code: Select all

-- Source: http://forums.obdev.at/viewtopic.php?t=137

property delim : " - "

on open (s)
   -- added the next line to make it work when LB is in nonactivating mode (by @ptujec)
   tell application "LaunchBar" to activate
   display dialog "Enter tags:" buttons {"Cancel", "OK"} default answer "" default button "OK"
   set result to text returned of result
   set theResult to result as text
   tell application "GrowlHelperApp"
      -- Make a list of all the notification types
      -- that this script will ever send:
      set the allNotificationsList to ¬
         {"Spotlight comments"}
      
      -- Make a list of the notifications
      -- that will be enabled by default.     
      -- Those not enabled by default can be enabled later
      -- in the 'Applications' tab of the growl prefpane.
      set the enabledNotificationsList to ¬
         {"Spotlight comments"}
      
      -- Register our script with growl.
      -- You can optionally (as here) set a default icon
      -- for this script's notifications.
      register as application ¬
         "SpotlightCommenter" all notifications allNotificationsList ¬
         default notifications enabledNotificationsList ¬
         icon of application "Spotlight"
   end tell
   tell application "Finder"
      repeat with this_item in s
         set item_name to (get displayed name of this_item)
         if item_name is not ".DS_Store" then
            set current_com to (get comment of this_item)
            if current_com does not contain theResult then
               if current_com is "" then
                  set comment of this_item to theResult
                  
               else
                  set comment of this_item to (current_com & delim & theResult) as string
                  
               end if
               tell application "GrowlHelperApp"
                  notify with name ¬
                     "Spotlight comments" title ¬
                     item_name description ¬
                     "Tagged \"" & theResult & "\"" application name "SpotlightCommenter"
               end tell
            else
               tell application "GrowlHelperApp"
                  notify with name ¬
                     "Spotlight comments" title ¬
                     item_name description ¬
                     "Already tagged \"" & theResult & "\"" application name "SpotlightCommenter"
               end tell
            end if
            
         end if
      end repeat
   end tell
end open

Posted: Tue Mar 10, 2009 2:56 pm
by derdiplomat
Thank You so much for that script.

What I didn’t like too much is the "press ⌘+D and then navigate via "down arrow" with the keyboard to confirm the action….

So I’m trying to figure out how to use the script saved as an Application.
I haven’t come far yet, since the selected files ought to be dropped on the app. Otherwise they would could be triggered instantly via Launchbar or with a predefined Shortcut using Shadow Lab.’s SPARK.

Whatever. Thanks again - best script I’ve seen so far - if anyone here know of an even faster way (without confirmation and ⌘+D) - let me know.

Cheers,
Patte

Posted: Tue Mar 10, 2009 10:17 pm
by susanspy
Hello all,

susan here, i am in love with his place truly deeply and madly, i have been to many forums but have not found a informative place like thsi one, i like the content very much here so thought to drop a few lines here.

Fred, script is perfect. many a million thanks dude.

Thanks all.

Cheers!!!

Posted: Wed Mar 11, 2009 3:06 pm
by ptujec
derdiplomat wrote:I didn’t like to press ⌘+D and the navigate to again vie the keyboard to confirm the action


I use "Instant Send" most of the time ... in my case I hold ctrl+space a bit longer ... than just typ "tag" ↩ and thats it.

Posted: Wed Mar 11, 2009 3:18 pm
by derdiplomat
ptujec wrote:
derdiplomat wrote:I didn’t like to press ⌘+D and the navigate to again vie the keyboard to confirm the action


I use "Instant Send" most of the time ... in my case I hold ctrl+space a bit longer ... than just typ "tag" ↩ and thats it.


Uhm… I never heard of "Instant Send" before ==> THANK YOU SO MUCH AGAIN!.

Note to myself: it always pays out to read the manual. I don’t know why I
did not kept that habit (… back in the days I used to read the whole manual of a famicon game before playing it :)).

Re: Adding spotlight tags?

Posted: Mon May 18, 2009 12:06 pm
by ob86
I never heard of "Instant Send" before ==> THANK YOU SO MUCH AGAIN!.

http://fleafreesmart.com/
http://www.mpos.net/

Re: Adding spotlight tags?

Posted: Wed Jun 24, 2009 7:31 am
by Hiram1
sure.. :D
why not....
welcome sonbob115 here. Are you new to the forum???

Re: Adding spotlight tags?

Posted: Mon Aug 03, 2009 5:50 pm
by Forumposter
I'm a bit offtopic, sorry.
But where does spotlight store the tags?
I want to burn them on CD (together with my tagged files) so another Mac user sees the tags.

Re: Adding spotlight tags?

Posted: Tue Aug 04, 2009 12:30 am
by sjk
Forumposter wrote:But where does spotlight store the tags?

These "tags" are stored as Spotlight Comments, which are stored in hidden .DS_Store files and also (on 10.5) the com.apple.metadata:kMDItemFinderComment extended attributes.

I want to burn them on CD (together with my tagged files) so another Mac user sees the tags.

Whether or not they'll be preserved depends on how you write the data and how it's restored. In general, I'd recommend creating a zip, dmg, tar, or other type of archive of the files that will also store their Spotlight Comment metadata, then burn that to CD. Or, maybe burning a Mac format data disc with Toast would do it tho' I don't know offhand.

Re: Adding spotlight tags?

Posted: Wed Aug 19, 2009 12:22 am
by ptujec
I rewrote the script a bit. Actually I mixed it with another one I found here: http://macscripter.net/viewtopic.php?pid=99577#p99577

The greatest benefit is the option to overwrite tags. And its more flexible in use.
(You can now 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 ... )

Code: Select all

-- »Spotlight Tags« - Add Spotlight comments to your files and folders (with LaunchBar or Finder)!
-- by Ptujec
--
-- version 1.1 (adds "Pop" sound)
--
-- Sources:
-- http://macscripter.net/viewtopic.php?pid=99577#p99577
-- http://forums.obdev.at/viewtopic.php?t=137
----------------------------------

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 with sound "Pop"
               end tell
            else
               tell application "LaunchBar"
                  display in large type "All items untagged!" as text with sound "Pop"
               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 with sound "Pop"
                  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 with sound "Pop"
                  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 with sound "Pop"
               end tell
               
            end if
         end repeat
      end if
      
   end tell
   
   -- option autohide
   -- tell application "LaunchBar"
   --   delay 1.5
   --   hide
   -- end tell
   
end tagging