Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ST2 Mountain Lion Notifier Access
import sublime
import sublime_plugin
from subprocess import call
import os.path as path
import urllib2
import os
from zipfile import ZipFile
from io import BytesIO
import platform
import json
import shutil
VERSION = "1.3.0"
URL = "https://github.com/downloads/alloy/terminal-notifier/terminal-notifier_%s.zip" % VERSION
APP = "terminal-notifier_%s/terminal-notifier.app/" % VERSION
APP_ROOT_DIR = "terminal-notifier_%s/" % VERSION
SCRIPT_PATH = path.dirname(path.abspath(__file__))
BIN = "terminal-notifier.app/Contents/MacOS/terminal-notifier"
NOTIFIER = path.join(SCRIPT_PATH, BIN)
VERSION_LOG = path.join(SCRIPT_PATH, "terminal-notifier.json")
CURRENT_VERSION = "0.0.0"
class NotifyCommand(sublime_plugin.ApplicationCommand):
def run(
self, message=None, title=None, group=None,
remove=None, activate=None, open_url=None, execute=None
):
if message != None or remove != None:
try:
params = [NOTIFIER]
if message != None:
params += ["-message", message]
if remove != None:
params += ["-remove", remove]
if title != None:
params += ["-title", title]
if group != None:
params += ["-group", group]
if activate != None:
params += ["-activate", activate]
if open_url != None:
params += ["-open", open_url]
if execute != None:
params += ["-execute", execute]
call(params)
except:
sublime.error_message("Error sending notifier message!")
return
else:
sublime.error_message("Bad Command!")
def is_enabled(self):
if sublime.platform() != "osx":
return False
v, _, _ = platform.mac_ver()
v = float('.'.join(v.split('.')[:2]))
return (v >= 10.8 and path.exists(NOTIFIER))
def get_notifier():
status = False
try:
unzip_notifier(urllib2.urlopen(URL))
j = json.dumps({"version": VERSION}, sort_keys=True, indent=4, separators=(',', ': '))
with open(VERSION_LOG, 'w') as f:
f.write(j + "\n")
except:
status = True
return status
def unzip_notifier(bfr):
z = ZipFile(BytesIO(bfr.read()), "r")
for name in z.namelist():
if name.startswith(APP):
file_name = name.replace(APP_ROOT_DIR, "")
if name.endswith("/"):
os.makedirs(path.join(SCRIPT_PATH, file_name))
else:
with open(path.join(SCRIPT_PATH, file_name), "wb") as f:
f.write(z.read(name))
os.chmod(path.join(SCRIPT_PATH, file_name), 0777)
z.close()
def init():
global CURRENT_VERSION
# Get current version if available
if path.exists(VERSION_LOG):
with open(VERSION_LOG, "r") as f:
CURRENT_VERSION = json.load(f)["version"]
# Get the notifier app if needed
# Upgrade if out of date
if not path.exists(NOTIFIER):
if get_notifier():
sublime.error_message("Failed to acquire terminal-notifier!")
else:
CURRENT_VERSION = VERSION
elif CURRENT_VERSION != VERSION:
try:
shutil.rmtree(path.join(SCRIPT_PATH, "terminal-notifier.app"))
except:
sublime.error_message("Failed to remove old version of terminal-notifer!")
return
if get_notifier():
sublime.error_message("Failed to acquire terminal-notifier!")
else:
CURRENT_VERSION = VERSION
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.