Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Search for AppleScript content in Spotlight System 10.4
Tiger only hintI want to be able to search for AppleScripts by content in Spotlight, but it seems there is not an importer plug-in for this (yet?). I know I can find them by name, but most of the time this is not enough. Like when I know there is a line I used in a script I want to look at again to see how I did part of it, but cannot remember what the script was called.

So I wrote a very quick and dirty AppleScript to open the currently selected script(s), copy their contents, paste them into the Spotlight comments field, close the Get Info window and script file, and move on to the next selection. I know there is probably a better (prettier) way to write this, but as I said, it did not take long to write.

Now in spotlight I can type something like keystroke scpt and get all the scripts which have the word keystroke in their content.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,457 views]  

10.4: Search for AppleScript content in Spotlight | 8 comments | Create New Account
Click here to return to the '10.4: Search for AppleScript content in Spotlight' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Search for AppleScript content in Spotlight
Authored by: GlowingApple on Jun 15, '05 11:32:28AM

Is this link broken? I get a 404 error when I try to download the file.

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
10.4: Search for AppleScript content in Spotlight
Authored by: mark hunte on Jun 15, '05 02:29:28PM
Emm... The link does seem to be down ??

Here is the Hopefully improved version.

( this one does not need to open the info window.. to put the comment in.,
I discoved that I could do this with set comment (which did not work before for me
as I had it in a Process application tell block instead of a normal one.,
Dougs Script in Robg's, hint showed me the way. http://www.macosxhints.com/article.php?story=20050614071122965)

 (* This script will open any selected scripts  and copy 
the contents, and paste them into the info window of the script file, the 
content can be found in spotlight

*)
property flag : ""
tell application "Finder"
	set SiTem to selection
	
	repeat with i from 1 to number of items in SiTem
		set this_item to item i of SiTem --as string
		
		tell application "System Events"
			tell process "finder"
				open this_item
				delay 1
				keystroke "a" using [command down]
				keystroke "c" using [command down]
				delay 1
				--keystroke "b" using [command down, control down] -- sticky brain grab
				my setComm(this_item, flag)
			end tell
		end tell
	end repeat
end tell

on setComm(this_item, flag)
	tell application "Finder"
		
		set comment of this_item to the clipboard
		
		tell application "Script Editor"
			close window of document 1
		end tell
		
	end tell
end setComm
Both scripts work ok.

---
mh

[ Reply to This | # ]

10.4: Search for AppleScript content in Spotlight
Authored by: jonn8n on Jun 15, '05 03:06:29PM
There's no need to use GUI scripting. Here's a version that has a little validation, doesn't overwrite existing comments (it appends the script to them), and can also be saved as a droplet so you can just drag and drop scripts on to it to set their comment:
--note, this will not work if a script has been saved as "Run Only"

property valid_extensions : {"scpt", "scptd"} --no need to add "applescript" since this is text and will be cataloged anyway
property valid_creator_types : {"ToyS", "aplt"}
property valid_file_types : {"osas"}

on run
	tell application "Finder" to set selected_items to (get selection)
	open selected_items
end run

on open selected_items
	tell application "Finder"
		repeat with i from 1 to (count selected_items)
			set this_item to item i of selected_items
			try
				set name_extension to name extension of this_item
				set creator_type to creator type of this_item
				set file_type to file type of this_item
			on error
				set {name_extension, creator_type, file_type} to {"", "", "folder"}
			end try
			if (name_extension is in valid_extensions) or (creator_type is in valid_creator_types) or (file_type is in valid_file_types) then
				set the_script_text to my get_script(this_item)
				if the_script_text is not "" then
					set old_comment to comment of this_item
					if old_comment is not "" then set old_comment to old_comment & return
					set comment of this_item to old_comment & the_script_text
				end if
			end if
		end repeat
	end tell
end open

on get_script(this_script)
	try
		tell application "Script Editor"
			open (this_script as alias)
			tell document 1
				set the_script_text to contents as Unicode text
				close
			end tell
		end tell
		return the_script_text
	on error
		return ""
	end try
end get_script
Jon

[ Reply to This | # ]
10.4: Search for AppleScript content in Spotlight
Authored by: mark hunte on Jun 15, '05 04:43:20PM

Thanks for the tip of " Unicode text " I did try ' set ...to contents...' but a had tried just as text.

For me there is no need to append to a Applescript comment, if I run my script on it, I want the whole lot replaced because thats reflects whats in the file, and not bits I may have taken out.

Also I like to run these type of script from hot keys.

I do like the checking for a script routine, but again for me there is no need as I only run this on Applescript.

But saying all that, I am sure your script will suit others just as well : )


---
mh



[ Reply to This | # ]
10.4: Search for AppleScript content in Spotlight
Authored by: mark hunte on Jun 15, '05 05:02:51PM
Ok just used the unicode text, and that makes the script much,Oh my god faster, Thanks again.
 (* This script will open any selected scripts  and 
copy the contents, and paste them into the info window 
of the script file, the content can be found in spotlight

*)
property the_script_text : ""
tell application "Finder"
	set SiTem to selection
	
	repeat with i from 1 to number of items in SiTem
		set this_item to item i of SiTem --as string
		
		tell application "Script Editor"
			open this_item
			tell document 1
				set the_script_text to contents as Unicode text 				close
			end tell
			--keystroke "b" using [command down, control down] -- sticky brain grab
			my setComm(this_item, the_script_text)
		end tell
		
	end repeat
end tell

on setComm(this_item, the_script_text)
	tell application "Finder"
		set comment of this_item to the_script_text
	end tell
end setComm
 

---
mh

[ Reply to This | # ]

Edit to above comment.
Authored by: mark hunte on Jun 15, '05 05:08:51PM

Make sure the 'close' is on the line below ' set the_script_text to contents as Unicode text '
like this

set the_script_text to contents as Unicode text
close

---
mh



[ Reply to This | # ]
10.4: Search for AppleScript content in Spotlight
Authored by: robJ on Jul 01, '05 10:37:35PM

If you use Script Debugger, there's now a Spotlight Importer available from Late Night Software.

http://www.latenightsw.com/sd3.0/spotlight.html

"The Script Debugger Spotlight Importer allows you to search the source code and the description of any compiled script saved with Script Debugger using Tiger's new Spotlight search capability."

-- Rob



[ Reply to This | # ]
Script Debugger Spotlight Importer not working
Authored by: ehouwink on Dec 30, '05 02:59:26PM

I have installed Script Debugger Spotlight Importer and waited until mdimport, mds had done reindexing but Spotlight doesn't find text in my compiled scripts.
Did anybody have better results...?



[ Reply to This | # ]