def startApps(self, apps): for _name in apps: if '"' in _name: raise Excetion("Strange app name %s" % _name) _cmd = "\n".join(map( lambda app: 'tell application "%s" to launch' % app, apps)) appleScript.execScript(_cmd)
def growl(self, type, title, text, priority=0, sticky=False): if type not in self.notificationTypes: self.notificationTypes += (type, ) self.register() _wrap = appleScript.escapeString _priority = min(max(priority, -2), 2) _appleScript = """ tell application "GrowlHelperApp" notify \ with name %(type)s \ title %(title)s \ description %(body)s \ application name %(appName)s \ sticky %(sticky)s \ priority %(priority)i end tell """ % { "appName": _wrap(self.appName), "type": _wrap(type), "title": _wrap(title), "body": _wrap(text), "sticky": "yes" if sticky else "no", "priority": _priority, } appleScript.execScript(_appleScript)
def _setActivated(self, status): if not self.isRunning(): raise EnvironmentError("Caffeine is not running") appleScript.execScript(""" tell application "Caffeine" turn %s end tell """ % ("on" if status else "off"))
def register(self): if not self.notificationTypes: raise ValueError("No notification types defined!") if not self.isGrowlRunning(): raise EnvironmentError("Growl is not running") _wrap = appleScript.escapeString _substArgs = { "progName": _wrap(self.appName), "noteList": ", ".join(map(_wrap, self.notificationTypes)), } _tellCmd = \ "register as application %(progName)s \ all notifications {%(noteList)s} \ default notifications {%(noteList)s}" if self.icon: _tellCmd += " icon of application %(icon)s" _substArgs["icon"] = _wrap(self.icon) _appleScript = "\n".join(( 'tell application "GrowlHelperApp"', _tellCmd % _substArgs, 'end tell', )) appleScript.execScript(_appleScript)