Home Download Buy Blog Forum Support

Open In Sublime (finder toolbar app for OS X)

Open In Sublime (finder toolbar app for OS X)

Postby pjv on Wed Feb 22, 2012 12:58 am

Open in sublime is a little finder toolbar app that will open the current folder in the sidebar of Sublime Text 2.

screenshot.png
screenshot.png (65.58 KiB) Viewed 8567 times


Grab it from the repo on github.
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

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

Postby jon4than on Wed Feb 22, 2012 3:52 pm

I like the idea, but it looks as though the path to subl in main.scpt is a hardcoded path specific to your machine. I was able to fix it by simply changing the path to the location within Sublime Text 2.app:
Code: Select all
do shell script "/Applications/Sublime\\ Text\\ 2.app/Contents/SharedSupport/bin/subl " & "'" & currentPath & "'"
jon4than
 
Posts: 2
Joined: Wed Feb 22, 2012 3:34 pm

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

Postby pjv on Thu Feb 23, 2012 1:55 am

jon4than wrote:I like the idea, but it looks as though the path to subl in main.scpt is a hardcoded path specific to your machine. I was able to fix it by simply changing the path to the location within Sublime Text 2.app:
Code: Select all
do shell script "/Applications/Sublime\\ Text\\ 2.app/Contents/SharedSupport/bin/subl " & "'" & currentPath & "'"


i can't believe i'm such an idiot.

thanks for the fix. github repo updated with fixed version of the app.

fwiw, i tried to come up with a way to let applescript find the path to Sublime Text 2 (in case user keeps it somewhere other than /Applications) and use that path to find the way to subl, but for some reason even when applescript had the path right, the do shell script command would bomb telling me that there was no such file

Code: Select all
set st2 to POSIX path of (path to application "Sublime Text 2")
set subl to st2 & "Contents/SharedSupport/bin/subl "

do shell script quoted form of subl & "'" & currentPath & "'"


i could see in the "results" box in the applescript editor that it was getting the path to subl right, but it never worked. so for now, thanks to you jon4than, hard coded to at least the right place.
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 2:02 am

Looks nice! I'm one of those troublemakers who keeps his apps organized instead of all in one folder, but I'm capable of editing the file to work on my machine.

Thanks for sharing!
n8gray
 
Posts: 7
Joined: Wed Feb 22, 2012 11:15 pm

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

Postby handycam on Thu Feb 23, 2012 12:58 pm

Can't you just drag the file to the Sublime icon in the Dock? That's what I do, for files and folders.
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 minimalweb on Thu Feb 23, 2012 2:25 pm

You can also drag the app itself to the toolbar and then drag files or folders on it to open them.
minimalweb
 
Posts: 10
Joined: Sun Oct 02, 2011 7:22 pm

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

Postby Naatan on Thu Feb 23, 2012 2:40 pm

Thanks for the script! I hadn't even thought about this yet, it's sure to make my work a bit more fluent.

I modified your script a bit to work on the current selection and fallback on the current folder if no file is selected, this way I can use it to open files or folders I have selected as well. I would have forked your script on Github and requested a pull, but it seems you haven't actually committed the code on github, so here are the modifications:

Code: Select all
-- script was opened by click in toolbar
on run
   
   tell application "Finder"
      copy selection to theSelected
      set outputPathList to {}
      repeat with anItem in theSelected
         copy (POSIX path of (anItem as alias)) to end of outputPathList
      end repeat
      set AppleScript's text item delimiters to return
      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 "/Applications/Sublime\\ Text\\ 2.app/Contents/SharedSupport/bin/subl " & "'" & currentPath & "'"
   end tell
   
end run


I don't know much about Applescript so I pretty much cut and paste this together from online resources, I'm sure that someone who has played around with Applescript more than I have can come up with a cleaner version, but this does the job.
Naatan
 
Posts: 20
Joined: Tue Feb 01, 2011 4:27 pm

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

Postby pjv on Thu Feb 23, 2012 3:24 pm

@handycam, @minimalweb: yes, you can do both of those things, the only thing that this little app adds in terms of convenience is the ability to do a one-click open of the current directory that is open in a finder window. 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, so it is convenient to have one-click ST2 access to that directory. it's not a big deal, i just like it and thought others might too.

@Naatan: i didn't commit the code because the app doesn't run as just a script and it seemed like a lot of extra work for people to open it up in applescript, save it as an app, copy paste the icon, etc. for such a simple little one-trick pony. but i will pull out the main script from the app and commit that. i thought about doing what you did in terms of opening the current selection, but then i realized that it was already easy to do that for files with a right-click "open with" from the finder and all i really wanted was for ST2 to open the current finder window folder. but i'm glad you made it work for you.

update: acchh, never mind. the main.scpt is binary too. there's really no code worth committing to the repo, i don't think.

i'm going to keep trying to find a solution that lets me dynamically find the way to the subl inside ST2 so that people who keep it somewhere other than /Applications could also use this without having to re-compile it. if i figure out how to make that work, i'll post back here and update the repo. but for anyone who wants to modify the behavior and/or location of subl, you can just open the app up in the applescript editor and make it do as you like.
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 4:10 pm

pjv wrote:i'm going to keep trying to find a solution that lets me dynamically find the way to the subl inside ST2 so that people who keep it somewhere other than /Applications could also use this without having to re-compile it. if i figure out how to make that work, i'll post back here and update the repo. but for anyone who wants to modify the behavior and/or location of subl, you can just open the app up in the applescript editor and make it do as you like.


ok, so i finally figured out how to find subl dynamically. i've updated the version of the app at github. here is the code that is in there, fwiw:

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"
      set currentPath to (POSIX path of (target of front window as string))
      tell current application to do shell script "\"" & subl & "\"" & " " & "'" & currentPath & "'"
   end tell
   
end run
pjv
 
Posts: 30
Joined: Fri Feb 04, 2011 6:34 pm

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

Postby Naatan on Thu Feb 23, 2012 6:08 pm

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.
Naatan
 
Posts: 20
Joined: Tue Feb 01, 2011 4:27 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Orlmente and 23 guests