Home Download Buy Blog Forum Support

Open In Sublime (finder toolbar app for OS X)

Re: Open In Sublime (finder toolbar app for OS X)

Postby handycam on Thu Feb 23, 2012 6:19 pm

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:

Screen Shot 2012-02-23 at 1.22.54 PM.jpg
Screen Shot 2012-02-23 at 1.22.54 PM.jpg (13.21 KiB) Viewed 3991 times
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby pjv on Thu Feb 23, 2012 6:53 pm

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.


thanks. done and i added a little readme too.
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby n8gray on Thu Feb 23, 2012 6:56 pm

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...

Code: Select all
-- script was opened by click in toolbar
on 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
   
end run
n8gray
 
Posts: 7
Joined: Wed Feb 22, 2012 11:15 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby pjv on Thu Feb 23, 2012 7:01 pm

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.
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby pjv on Thu Feb 23, 2012 7:09 pm

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.
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby svenax on Thu Feb 23, 2012 8:01 pm

On a related note, you can also easily create a service to open the selected files or folders in Sublime Text.

Using Automator, create a new service and configure it like this:

Image

Save as, for instance, Open in Sublime Text 2. Done.

To make it even more convenient, you can assign a keyboard shortcut to the service in System Preferences / Keyboard.
svenax
 
Posts: 151
Joined: Tue Dec 20, 2011 12:47 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby pjv on Sun Jul 15, 2012 9:24 pm

Version 2.0 of Open In Sublime is available on github.

Version 2 is a complete re-write with some new features.

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.
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

Re: Open In Sublime (finder toolbar app for OS X)

Postby Luke on Mon Jul 01, 2013 6:22 pm

svenax wrote:On a related note, you can also easily create a service to open the selected files or folders in Sublime Text.

Using Automator, create a new service and configure it like this:

Image

Save as, for instance, Open in Sublime Text 2. Done.

To make it even more convenient, you can assign a keyboard shortcut to the service in System Preferences / Keyboard.


I really like this. Although the command line should be:

Code: Select all
open -a "Sublime Text 2" --args -n $@


Will continue to work, even if the internal binary moves. And when Sublime Text 3 comes out, you can just remove the " 2" part.
Luke
 
Posts: 11
Joined: Sat Feb 19, 2011 6:09 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: Google [Bot], sapphirehamster and 13 guests