Sublime Text is a great text editor. Here's a little AppleScript that can help open folders or files selected in the finder directly with Sublime Text 3. To use the script:
- Open AppleScriptEditor
- Open a new editor (File -> New)
- Paste the code below into the editor
- Press the compile button to make sure it was copied correctly
- Export as an Application (File -> Export, Make sure you select 'Application' as the File Format. I usually save my scripts to '~/Library/Scripts' but the location isn't so important.
- Drag your newly saved application onto the Finder's toolbar
- That's it. Just press it whenever you want to open selected Files/Folders in Sublime Text 3
- You can change the icon on your new Application by following these instructions.
(*
Open in Sublime Text
To use:
* Drag Open In TextMate to the toolbar of any finder
window to add it to the toolbar
*)
on run
tell application "Finder"
if selection is {} then
set finderSelection to folder of the front window as string
else
set finderSelection to selection as alias list
end if
end tell
subl(finderSelection)
end run
-- script was drag-and-dropped onto
on open (theList)
subl(theList)
end open
-- open in Sublime Text
on subl(listOfAliases)
tell application "Sublime Text"
activate
open listOfAliases
end tell
end subl
2 comments:
Hi,
I was using your script for a while ago, but noticed that the startup was sluggish when sublime was not already running.
Found the following applescript to work a little better (from https://forum.sublimetext.com/t/open-in-sublime-finder-toolbar-app-for-os-x/4538/13 (NGRAY)):
-- 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
Post a Comment