Adding spotlight tags?

Sharing and discussing custom actions for LaunchBar
macsterdam
Rank 2
Rank 2
Posts: 41
Joined: Thu Nov 16, 2006 5:22 pm

Adding spotlight tags?

Postby macsterdam » Wed Dec 13, 2006 12:11 pm

Is it possible, or will ik be possible to add Spotlight tags to files/folders via LB?

FredB
Rank 2
Rank 2
Posts: 69
Joined: Sun Dec 31, 2006 8:19 am
Location: Liège, Belgium
Contact:

Re: Adding spotlight tags?

Postby FredB » Sun Dec 31, 2006 9:11 am

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.

SpiralOcean
Posts: 19
Joined: Mon Nov 13, 2006 1:13 am

Postby SpiralOcean » Sun Dec 31, 2006 8:02 pm

Thanks for posting this Fred!

macsterdam
Rank 2
Rank 2
Posts: 41
Joined: Thu Nov 16, 2006 5:22 pm

Postby macsterdam » Mon Jan 08, 2007 1:59 pm

Thanks very much indeed - haven't tried it yet, but will shortly! Much appreciated!

friedmandesigns
Posts: 1
Joined: Sun Jul 22, 2007 8:44 am
Location: tranquil cove near seattle, wa.
Contact:

FredB - thanks much.

Postby friedmandesigns » Sun Jul 22, 2007 8:49 am

Fred, script is perfect. many thanks. :)

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

addition for "Nonactivating Mode"

Postby ptujec » Sun Jan 11, 2009 7:45 pm

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

derdiplomat
Rank 1
Rank 1
Posts: 28
Joined: Wed Apr 23, 2008 8:45 pm

Postby derdiplomat » Tue Mar 10, 2009 2:56 pm

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
Last edited by derdiplomat on Tue Mar 10, 2009 11:25 pm, edited 1 time in total.

susanspy
Posts: 1
Joined: Tue Mar 10, 2009 12:56 pm

Postby susanspy » Tue Mar 10, 2009 10:17 pm

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!!!
Last edited by susanspy on Wed Mar 25, 2009 12:31 pm, edited 1 time in total.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Postby ptujec » Wed Mar 11, 2009 3:06 pm

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.

derdiplomat
Rank 1
Rank 1
Posts: 28
Joined: Wed Apr 23, 2008 8:45 pm

Postby derdiplomat » Wed Mar 11, 2009 3:18 pm

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 :)).

ob86
Posts: 1
Joined: Tue May 05, 2009 9:28 am

Re: Adding spotlight tags?

Postby ob86 » Mon May 18, 2009 12:06 pm

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

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

Hiram1
Posts: 1
Joined: Fri Jun 19, 2009 12:13 pm

Re: Adding spotlight tags?

Postby Hiram1 » Wed Jun 24, 2009 7:31 am

sure.. :D
why not....
welcome sonbob115 here. Are you new to the forum???
Last edited by Hiram1 on Sat Feb 06, 2010 3:21 pm, edited 1 time in total.

Forumposter
Posts: 18
Joined: Wed Jul 29, 2009 7:56 pm

Re: Adding spotlight tags?

Postby Forumposter » Mon Aug 03, 2009 5:50 pm

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.

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: Adding spotlight tags?

Postby sjk » Tue Aug 04, 2009 12:30 am

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.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Adding spotlight tags?

Postby ptujec » Wed Aug 19, 2009 12:22 am

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
Last edited by ptujec on Tue Dec 08, 2009 4:19 pm, edited 2 times in total.


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 1 guest