Hello,
currently I am looking for a plugin that can launch various local files or directories with the operating system file manager or the corresponding app. It should also be able to launch websites in the browser.
Ideally I would like to define various launch items (local files (e.g. office files, pdfs), local directories and web sites) in an user settings file and call the launcher either via a shortcut or command palette. After launching I can fuzzy select the thing I would like to launch.
I have looked at PackageControl but I didn’t found one. Although being a newbie myself I started to write a plugin myself.
First here is a rough sketch that outlines my idea, currently the launcher can be launched via the console with the command window.run_command("launcher")
.
Before I spent more time to developing it I would like to know if a similar package is already there. If not I will try to enhance it and will post it to github if it can do more.
Current tasks:
- find out how to bind
window.run_command("launcher")
to a keymap (solved) - adding launch command to command palette & to the tools menu (solved)
- build a correct package
- add checks & exceptions
- find out how to get the
launch_items
definition in the users package settings of the plugin and how to parse that - adding an addition layer to the launcher that contains a third value like file, url, file+subl (where file+subl would open the file directly in ST 3)
Any feedback or pointing to the right direction would be appreciated.
import sublime
import sublime_plugin
import os
import subprocess
import sys
import webbrowser
launch_items = {
"Head First Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Head First Python\\Head First Python.pdf",
"Introducing Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Introducing Python\\Introducing Python.pdf",
"Python Cookbook": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Python Cookbook\\Python Cookbook.pdf",
"Programming Python": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\Programming Python\\Programming Python.pdf",
"O' Reilly Apps Directory": "C:\\Users\\bine\\Dropbox\\apps\\O'Reilly Media\\",
"Sublime Text 3 - Api Reference": "http://www.sublimetext.com/docs/3/api_reference.html"
}
class LauncherCommand(sublime_plugin.WindowCommand):
def run(self):
items = sorted(list(launch_items.keys()))
self.window.show_quick_panel(items, self.on_done)
def on_done(self, choice):
if choice >= 0:
items = sorted(list(launch_items.keys()))
path = launch_items[items[choice]]
if path.startswith('http://') or path.startswith('https://'):
webbrowser.open(path, 2, True)
return
if not os.path.exists(path):
sublime.message_dialog(
'"' + path + '"' +
"isn't a valid path and can't be opened!")
return False
# Windows
if os.name == "nt":
os.startfile(path)
# Macintosh - not tested yet
elif sys.platform == "darwin":
subprocess.call(['open', path])
# Generisches Unix (X11) - not tested yet
else:
subprocess.call(['xdg-open', path])