Dragthing, AppleScripts and hot keys

Nov 30, '01 02:16:58PM

Contributed by: james_sorenson

Okay, here is a quick run-down of how I fully utilize the power of DragThing. DragThing is a MacOS utility that provides multiple tabbed docks to store aliases, web links, etc. It also has a process dock that acts much like the MacOS X dock (with some customization differences).

What really hooked me, though, was the ability to add hot-keys and applescripts.

Read the rest of this article for some useful examples of both hot keys and AppleScripts with Drag Thing, including a script to automatically display an updated listing of your volumes in a dock layer.

Let's start with something simple. You want to be able to assign a hot-key that will open a selected file in the Finder into a favorite application. For instance: Select one or more files in the Finder, then hit cmd-cntrl-b to open those files into BBEdit.

Create the following applescript (using ScriptEditor) and save it as a compiled script (not an application):

--OpenWithBBEdit.scpt 
--path to the BBEdit application
set BBEdit to "Sorenson:Applications:Office:BBEdit:BBEdit 6.5"
tell application "Finder"
open selection using BBEdit
end tell
I believe Apple has already given you a Scripts folder in your Library folder to save such things. Now drag that script to a slot in DragThing. I have a layer that is dedicated to holding hot-key scripts. Right-click on the script in DragThing and select "Item Options...". Click "Use Hot Key to open item" and click on the bar to assign it the cmd-cntrl-b combination.

That's it! From here on, you can select a file, and hit cmd-cntrl-b to open it in BBEdit. You can create other scripts for all your often-used apps.

Notice that you can also make a hot-key to bring the finder to the front with this script:
--ActivateFinder.scpt 
tell application "Finder"
activate
end tell
Now, let's say you want to make a DragThing layer hold all your volumes (including temporary volumes!). Create the following script, and give it a hotkey. Now, everytime you hit that hot-key, DragThing will appear, switch to the Disks layer, and update the slots with your mounted volumes. Slick, eh??
--DragThingDisks.scpt
--This script will bring Dragthing to the front, add/update a list of
--mounted volumes to the dock and layer specified onthe first two lines,
--and switch to that layer.
--
--The savedslots variable refers to to how many slots you want to be left
--alone. For instance, if you wish to keep your Home and Temporary
--directory in the top two slots, set savedslots to 2.
--
--Shortcomings: You'll notice that any network volumes that have the base
--directory mounted can not be perused. This is a limitation imposed by
--DragThing due to complications in MacOSX.

set diskdock to "Main"
set disklayer to "Files"
set savedslots to 2

--Get the list of mounted volumes from the Finder
tell application "Finder"
set disklist to the name of every disk as list
end tell

--Count the mounted volumes
set disknumber to number of items in disklist

tell application "DragThing"
activate
--switch to the disk layer
select layer disklayer of dock diskdock

--Count the number of slots available in the layer
set maxslots to the number of slots of layer disklayer of dock diskdock

--Make sure the number of volumes doesn't exceed the size of the layer
if disknumber > (maxslots - savedslots) then
set disknumber to (maxslots - savedslots)
end if

--Add each volume one at time
set n to 1
set m to 0
repeat until n > disknumber
if (item n of disklist as string) contains "Servers" then
--ignore and adjust marker
set m to 1
else
--add the volume
set file location of slot (n + savedslots) of layer disklayer of ¬
dock diskdock to file (((item n of disklist) & ":") as string)
end if
set n to n + 1
end repeat

--clear any leftover volumes from the layer
set n to n + savedslots - m
repeat until n > maxslots
delete slot n of layer disklayer of dock diskdock
set n to n + 1
end repeat
end tell
DragThing can be found at dragthing.com. If you have questions or comments on these scripts, please post them here...

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011130141658677