A nifty little Finder Toolbar Applet/Droplet

Hello.

I have made a little applet i figure will be usable, since there are certain scripts I like to have quick access to.

It works like this: you click on the droplet you have installed on the finder toolbar, and you’ll get presented a list with scripts, that you can run. (Not script bundles.) When you have a script you’d like to see on that menu, you just drag and drop the script onto the toolbar icon. (I used the Generic Preferences icon, from the “/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/” folder, opened it in preview, copied the image, and pasted it onto the icon in the droplets icon, in the file-information dialog of finder.
I also inserted the item that says that “application is an agent” in the plist file, within its Contents folder.

So I have made an applet, with an extra folder : “HelperScripts”, and inside that folder a folder named Obsolete, so I have a place to put the scripts I am not currently using.

There is one script that comes with it, and that is the one named OpenHelperScriptsFolder.

Caveats:
You’ll have to see to that the scripts you stuff it with, has an ‘.scpt’ extension, and that extension aren’t hidden in Finder.

Edit

The caveat still exists, if you drag files into the folder, but the open handler takes care of the problem when scripts are dropped onto it.

Edit++
I have resolved the second issue, when you drop a file with either no name extension or name extension hidden,
by fixing it. This leads however to a somewhat slower script execution the times you modify the folder by dropping items into it, one way or the other.

I hope you like it still. :slight_smile:

The Applet (you must save it as an application bundle).

-- © 2013 Copyright McUsr and put in public domain
-- Icon copyright © Apple Inc.
property app_nm : "Servant"
property lastmodDate : ""
on run
	script o
		property l : {}
	end script
	local helpScriptsFolder, md
	set helpScriptsFolder to (path to resource "HelperScripts") as text
	tell application "Finder"
		set md to modification date of folder helpScriptsFolder
		if md ≠ lastmodDate then
			set o's l to every document file of folder helpScriptsFolder
			local tc
			set tc to (count o's l)
			repeat with i from 1 to tc
				if extension hidden of item i of o's l is true then
					set extension hidden of item i of o's l to false
				end if
				if name extension of item i of o's l is "" then
					set name extension of item i of o's l to "scpt"
				end if
			end repeat
			set lastmodDate to md
		end if
	end tell
	local helperScripts, app_path
	set app_path to POSIX path of (path to me)
	set app_path to app_path & "/Contents/Resources/HelperScripts"
	
	set helperScripts to paragraphs of (do shell script "ls -1 " & quoted form of app_path & " |sed -n 's/.scpt$//p'")
	
	tell me
		activate
		set run_script to choose from list helperScripts default items item 1 of helperScripts with title "Servant" with prompt "Choose a Script to run"
	end tell
	if run_script = false then
		tell application "Finder" to activate
		error number -128
	end if
	set run_script to POSIX file (app_path & "/" & run_script & ".scpt") as alias
	
	tell application "AppleScript Runner" to run script run_script
	tell application "Finder" to activate
end run

on open the_items
	set app_path to (path to me as text) & "Contents:Resources:HelperScripts" as alias
	tell application "Finder"
		repeat with anItem in the_items
			if extension hidden of anItem is true then
				set extension hidden of anItem to false
			end if
			if name extension of anItem is "" then
				set name extension of anItem to "scpt"
			end if
			move anItem to folder app_path replacing no
		end repeat
	end tell
	
end open

The helper script that opens the HelperScriptsFolder.

-- © 2013 Copyright McUsr and put in public domain
-- Icon copyright © Apple Inc.
set app_path to POSIX path of (path to current application)
set app_path to app_path & "/Contents/Resources/HelperScripts"
do shell script "open " & quoted form of app_path

I have a ready made version here

Hi,

I’m wondering why so many people are scared of HFS paths nowadays

You coerce path to me “ which is an alias anyway “ to alias, POSIX path, POSIX file and back to alias
This is sufficient, it results a HFS path to be the proper argument for the Finder folder specifier.
No coercion is needed at all


set app_path to (path to me as text) & "Contents:Resources:HelperScripts:"

Hello.

Laziness, I use mdfind, to locate applets, while I am writing the code, and afterwards, it didn’t strike me as unecessary. I am not afraid of hfs paths, though posix paths are easier for interacting with shell-utilities.

Edit

I did change it in the open handler, for the aestethics. :wink:

The most versatile path representation for AppleScript is HFS path.

You can coerce a HFS path directly to POSIX path and make an alias by putting the alias specifier in front of it.
A POSIX path needs always two steps POSIX file and text / alias coercion to get an HFS path / alias

Posix path interacts better with shell utilities, and System Events interacts splendidly with posix paths too. Maybe I don’t use hfs paths as often as I should, but I use Applescript mostly as a glue language, and then I need the posix paths for interfacing with the other stuff.

Hello.

I have updated it slightly, so that it sets the name extension hidden to false, and adds a missing file ext, if it was missing, for scripts that are dropped onto it.

In general:
First of all avoid alias as much as you can unless you need persistent file names or create them at the last line. edit: (see example code below)

What remains is more a file vs POSIX file thing. When the command can handle file URLs you should use POSIX file instead. I’ve always though that file and POSIX file were both file URLs in the background but it seems that file reference is converted to Unicode string inside an Apple Event while POSIX path is an file URL.

edit: After some testing I found that the old file reference for load, store and run script command won’t be coerced into an file URL but is coerced into a Unicode text class. I though it did so my mistake and corrected this post. Here an example code:

run script alias "Volume:test.scpt" --path is send as Alias (alis)
run script file "Volume:test.scpt" --path is send as Unicode Text (utxt)
run script POSIX file "/test.scpt" --path is send as file URL (furl

According to technical note TN2022 you should use file URL.

It’s not that we’re scared it’s suggested by Apple, the Finder supports file URL too so you should use POSIX file references in the Finder.

Hello.

I have resolved the second issue, when you drop a file with either no name extension or name extension hidden, by fixing it. This leads however to a somewhat slower script execution, the times you modify the folder by dropping items into it, one way or the other.
I hope you like it still. :slight_smile:

I’m chuckling of your new signature DJ Bazzie Wazzie, well there are help to be found: I dug up this ancient article from the wayback archieve, and it is quite helpful, at least for me.

Hello.

I didn’t like the droplet/applet as it was, as it wasn’t quite so responsive as I wished for, when new scripts were dropped into the folderresiding in the contents of the applet. This due to the fact, that the applet is per se changed when a new script is stuffed into it, so that the first click on the toolbar is used to register it, and the next click will have a slow responce. Unbearable! So I made it create a folder in the application support folder, if it doesn’t exist. (I check for this both in the run and the open handler). I have also given it a new name (Q for quick), and new uti, so that you get the chance to restuff your scripts into the application folder once it has been created (upon first run).

I recommend you save the first version however, because it is very usable for a static configuration of scripts, than the second version.

Maybe it will be a third round here, rethinking the update logic, and maybe implementing mdfind, or turn things around in other ways.

In the mean time, enjoy!


-- © 2013 Copyright McUsr and put in public domain
-- Icon copyright © Apple Inc.
property app_nm : "Q"
property isdebugging : true

property lastmodDate : ""
on run
	script o
		property l : {}
	end script
	local helpScriptsFolder, md, appsupp
	try
		set appsupp to path to application support folder from user domain
		
		set helpScriptsFolder to (path to resource "HelperScripts") as text
		
		tell application "Finder"
			
			if not (exists folder "Q" of folder appsupp) then
				make new folder at folder appsupp with properties {name:"Q"}
				duplicate file "OpenHelperScriptsFolder.scpt" of folder helpScriptsFolder to folder "Q" of folder appsupp
			end if
			set helpScriptsFolder to folder "Q" of folder appsupp as alias
			set md to modification date of folder helpScriptsFolder
			if md ≠ lastmodDate then
				set o's l to every document file of folder helpScriptsFolder whose name extension is "scpt"
				local tc
				set tc to (count o's l)
				repeat with i from 1 to tc
					if extension hidden of item i of o's l is true then
						set extension hidden of item i of o's l to false
					end if
					if name extension of item i of o's l is "" then
						set name extension of item i of o's l to "scpt"
					end if
				end repeat
				set lastmodDate to md
			end if
		end tell
		
		local helperScripts, app_path
		
		set helperScripts to paragraphs of (do shell script "ls -1 " & quoted form of (POSIX path of helpScriptsFolder) & " |sed -n 's/.scpt$//p'")
		tell me
			activate
			set run_script to choose from list helperScripts default items item 1 of helperScripts with title "Q" with prompt "Choose a Script to run"
		end tell
		if run_script = false then
			tell application "Finder" to activate
			error number -128
		end if
		set run_script to (helpScriptsFolder as text) & run_script & ".scpt" as alias
		
		tell application "Finder"
			run script run_script
			activate
		end tell
	on error e number n
		if isdebugging then
			my logit("Q: " & e & " " & n, "Q")
		end if
	end try
	
end run

on open the_items
	local appsupp, helpScriptsFolder
	try
		set helpScriptsFolder to (path to resource "HelperScripts") as text
		set appsupp to path to application support folder from user domain
		tell application "Finder"
			if not (exists folder "Q" of folder appsupp) then
				make new folder at folder appsupp with properties {name:"Q"}
				duplicate file "OpenHelperScriptsFolder.scpt" of folder helpScriptsFolder to folder "Q" of folder appsupp
			end if
			set helpScriptsFolder to folder "Q" of folder appsupp as alias
			repeat with anItem in the_items
				if extension hidden of anItem is true then
					set extension hidden of anItem to false
				end if
				if name extension of anItem is "" then
					set name extension of anItem to "scpt"
				end if
				move anItem to folder helpScriptsFolder replacing no
			end repeat
		end tell
	on error e number n
		if isdebugging then
			my logit("Q: " & e & " " & n, "Q")
		end if
	end try
end open

to logit(log_string, log_file)
	do shell script ¬
		"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
		"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit


The new version, named Q, can be found here.

I had stored the wrong OpenHelperScript.scpt in the applet bundle.

That is now changed, into this:

-- © 2013 Copyright McUsr and put in public domain
-- Icon copyright © Apple Inc.
set app_path to (POSIX path of (path to application support folder from user domain)) & "Q/"
do shell script "open " & quoted form of app_path

I am sorry for any inconvenience.

For some reason, the applet would require two clicks on the toolbar, when new script has been transferred to the ~/Application Support/Q folder in order to show the choose from list with scripts to execute, maybe on the selected files in the current finder window.

That problem is gone now, due to try error clauses, that doesn’t catch anything within those blocks!

This is one of the things I am more satifisied with by the way. It is a great boon, to be able to drop script that works with files just onto the toolbar icon, later you select files in the finder window, click the icon, and selects a script that does something to the selection. I’ll probably give this applet its own page on a site one day.

In the mean time, you can Download it from here

Enjoy :slight_smile:

Hello.

I have updated Q, since AppleScript runner no longer are with us. (Maverick.)

You can still download it from here.

I have also updated the “main.scpt” in post #9.