def notify(title, text=''): """Show a notification.""" if not boolvar('SHOW_NOTIFICATIONS'): return v = Variables(title=title, text=text) print(v)
def test_variables_multiple_args(infopl): """Variables: multiple args.""" arg = ['one', 'two'] js = '{"alfredworkflow": {"arg": ["one", "two"]}}' v = Variables(arg=arg) assert v.obj == {'alfredworkflow': {'arg': arg}} assert str(v) == js assert unicode(v) == js
def main(wf): snippet_body = os.getenv("snippetBody") # var_names = os.getenv("varNames").split() variables = {} # for var_name in var_names: # variables.update({var_name : os.getenv(var_name)}) v = Variables(**variables) v.config = { "clipboardtext" : snippet_body } print(v)
def test_variables_multiple_args(infopl): """Variables: multiple args.""" arg = ["one", "two"] js = '{"alfredworkflow": {"arg": ["one", "two"]}}' v = Variables(arg=arg) assert v.obj == {"alfredworkflow": {"arg": arg}} assert str(v) == js assert str(v) == js
def test_variables_unicode(): """Unicode handled correctly.""" v = Variables(arg="fübar", englisch="englisch") v["französisch"] = "französisch" v.config["über"] = "über" d = { "alfredworkflow": { "arg": "fübar", "variables": {"englisch": "englisch", "französisch": "französisch"}, "config": {"über": "über"}, } } print((repr(v.obj))) print((repr(d))) assert v.obj == d # Round-trip to JSON and back d2 = json.loads(str(v)) assert d2 == d
def main(wf): try: data = wf.args[0].split(" ") if len(data) != 2: return 1 [key, value] = data wf.logger.debug('Saving %r', key) if key in ['user', 'org']: wf.store_data(key, value) print(Variables('Set your %s to "%s"' % (key, value))) elif key == 'token': wf.save_password('ghpr-api-key', value) print(Variables('Saved your API token in Keychain')) else: return 1 except Exception as err: wf.logger.debug('err=%r', err) return 1
def test_variables_unicode(): """Unicode handled correctly.""" v = Variables(arg=u'fübar', englisch='englisch') v[u'französisch'] = u'französisch' v.config[u'über'] = u'über' d = { 'alfredworkflow': { 'arg': u'fübar', 'variables': { 'englisch': u'englisch', u'französisch': u'französisch', }, 'config': {u'über': u'über'} } } print(repr(v.obj)) print(repr(d)) assert v.obj == d # Round-trip to JSON and back d2 = json.loads(unicode(v)) assert d2 == d
def test_variables_unicode(): """Unicode handled correctly.""" v = Variables(arg=u'fübar', englisch='englisch') v[u'französisch'] = u'französisch' v.config[u'über'] = u'über' d = { 'alfredworkflow': { 'arg': u'fübar', 'variables': { 'englisch': u'englisch', u'französisch': u'französisch', }, 'config': {u'über': u'über'} } } print(repr(v.obj)) print(repr(d)) assert v.obj == d # Round-trip to JSON and back d2 = json.loads(unicode(v)) assert d2 == d
def do_toggle_alfred_sorts(wf): """Toggle "Alfred sorts results" setting.""" ctx = Context(wf) v = ctx.getbool('ALFRED_SORTS_RESULTS') if v: new = '0' status = 'off' else: new = '1' status = 'on' log.debug('turning "ALFRED_SORTS_RESULTS" %s ...', status) set_config('ALFRED_SORTS_RESULTS', new) print(Variables(title='Alfred sorts results', text='Turned ' + status))
def do_toggle_show_query(wf): """Toggle "show query in results" setting.""" ctx = Context(wf) v = ctx.getbool('SHOW_QUERY_IN_RESULTS') if v: new = '0' status = 'off' else: new = '1' status = 'on' log.debug('turning "SHOW_QUERY_IN_RESULTS" %s ...', status) set_config('SHOW_QUERY_IN_RESULTS', new) print(Variables(title='Show query in results', text='Turned ' + status))
def test_variables_empty(): """Empty Variables returns empty string.""" v = Variables() assert unicode(v) == u'' assert str(v) == ''
def test_variables_plain_arg(): """Arg-only returns string, not JSON.""" v = Variables(arg=u'test') assert unicode(v) == u'test' assert str(v) == 'test'
def test_variables_empty(): """Empty Variables returns empty string.""" v = Variables() assert str(v) == "" assert str(v) == ""
def test_variables_plain_arg(): """Arg-only returns string, not JSON.""" v = Variables(arg="test") assert str(v) == "test" assert str(v) == "test"
def test_variables(): """Set variables correctly.""" v = Variables(a=1, b=2) assert v.obj == {'alfredworkflow': {'variables': {'a': 1, 'b': 2}}}
def test_variables_config(): """Set config correctly.""" v = Variables() v.config['var'] = 'val' assert v.obj == {'alfredworkflow': {'config': {'var': 'val'}}}
def test_variables(): """Set variables correctly.""" v = Variables(a=1, b=2) assert v.obj == {"alfredworkflow": {"variables": {"a": 1, "b": 2}}}
def test_variables_config(): """Set config correctly.""" v = Variables() v.config['var'] = 'val' assert v.obj == {'alfredworkflow': {'config': {'var': 'val'}}}
def test_variables_config(): """Set config correctly.""" v = Variables() v.config["var"] = "val" assert v.obj == {"alfredworkflow": {"config": {"var": "val"}}}
def return_for_flow(result): v = Variables(result) print(v)
#!/usr/bin/python # encoding: utf-8 import sys, os, json from subprocess import Popen, PIPE, CalledProcessError from workflow import Workflow3, Variables from workflow.util import run_command log = None v = Variables() # With 1Password session key and a vault item UUID, request info for that item def main(wf): # Get cached 1Password session key session_key = wf.stored_data('session_key') if session_key is None: v.arg = 'Vault authentication has expired or is not valid' return args = wf.args op = args[0] jq = args[1] uuid = args[2] action = args[3] # Issue bash command to request item info from 1Password item_raw = None return_code = 0 try: command_output = Popen([op, 'get', 'item', uuid, '--session', session_key], stdout=PIPE)