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


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: 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 | # ]