Opening Sublime Text files in other applications

Published
2013-09-16
Tagged

Here’s a simple plugin for Sublime Text that you can modify to suit your own needs.

I often find myself using different plain-text apps for different purposes. Sublime Text is my go-to app for coding and technical writing, mainly due to all the usual factors: syntax highlighting, snippets, plugins and so on. However, I often find myself switching to Byword for longer-form writing, or just when I want a more prose-friendly environment. Unfortunately, Sublime Text lacks an “Open in…” menu item like you see in, for example, Notational Velocity. What it does have is incredible support for plugins, so I figured it wouldn’t be too hard to make one for my purposes.

In fact, it’s ridiculously easy. Here’s the sum total of code needed to make an “Open in Byword” command:

1
import sublime, sublime_plugin, subprocess
2
3
class OpenInBywordCommand(sublime_plugin.TextCommand):
4
  def run(self, edit):
5
    subprocess.Popen(["open", "-a", "Byword.app", self.view.file_name()])

By using the OS X command open you even bypass the work of locating the app.