if you want to drag a folder onto the ST2 icon to open it up, your finder window has to be showing you the parent of the directory you are interested in. i find that i often am looking at the contents of the directory that i want to work in

In that case, you can drag the proxy icon of the folder in the Finder window titlebar to your dock icon:

Naatan wrote:I see you've committed it on github as a txt, just a suggestion, if you rename it to code.applescript (or "open in sublime.applescript" for that matter), people can just double click it and save it as an app for easy compilation.

Here's my version that integrates Naatan's changes (and fixes a bug when you select multiple files to open) with automatic location of the app bundle. This one seems to do exactly what I want, except for one thing -- I wish there was a way to make it so option-clicking would open a new window for the file(s) instead of opening them in tabs of an existing window. But my applescript-fu is very weak...

-- script was opened by click in toolbaron run set st2 to POSIX path of (path to application "Sublime Text 2") set subl to st2 & "Contents/SharedSupport/bin/subl"

tell application "Finder" copy selection to theSelected set outputPathList to {} repeat with anItem in theSelected copy "'" & ((POSIX path of (anItem as alias)) as string) & "'" to end of outputPathList end repeat set AppleScript's text item delimiters to " " set currentPath to outputPathList as string set AppleScript's text item delimiters to "" if currentPath is equal to "" then set currentPath to "'" & (POSIX path of (target of front window as string)) & "'" end if tell current application to do shell script "'" & subl & "' " & currentPath end tell

handycam wrote:In that case, you can drag the proxy icon of the folder in the Finder window titlebar to your dock icon:

i bow down. thanks for that cool tip.

i still like the 1-click finder window toolbar applet better than a click and drag though.

also, for whatever reason, if you put ST2 in the toolbar and drag from the proxy icon to it, it looks to me like it only adds an alias to the sidebar in ST2 that doesn't resolve to the directory you want to see.

n8gray wrote:Here's my version that integrates Naatan's changes (and fixes a bug when you select multiple files to open) with automatic location of the app bundle. This one seems to do exactly what I want, except for one thing -- I wish there was a way to make it so option-clicking would open a new window for the file(s) instead of opening them in tabs of an existing window. But my applescript-fu is very weak...

my applescript-fu is also very weak and not likely to get much better i'm afraid because it has got to be one of the most opaque, unwieldy languages i have ever messed with.

subl will open a new window if you include -n in the command line and here is a little thread i found that talks about a maybe cumbersome way to figure out if the applescript is launched with the option key down. YMMV.

1. It works with Path Finder as well as Finder, and it also works better with Total Finder

2. By popular demand and the work of ProLoser, this verison of Open in Sublime lets it open the finder selection in Sublime Text 2. You can have either the original behavior or the open selection behavior depending on how you name the application that you create in AppleScript. If you name the app "open folder in sublime" then you will get the original behavior which is to always load the open finder (path finder) window in Sublime's sidebar regardless of whether there is a selection in the window or not. If you name it anything else, then you will get the new behavior which is to open the selection if there is one and the directory if there is not.