Skip to content

Commit

Permalink
Use Alfred's new AppleScript calls to set variables
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jul 8, 2018
1 parent dc7b157 commit 4362a97
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
Binary file not shown.
101 changes: 49 additions & 52 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search all fields</string>
<string>Search common fields</string>
<key>title</key>
<string>Search Zotero</string>
<key>type</key>
Expand Down Expand Up @@ -955,48 +955,15 @@ EOS</string>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>./zh citations "$id" "$1"
</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string></string>
<key>type</key>
<integer>5</integer>
<key>withspace</key>
<false/>
<key>triggerid</key>
<string>copy-citation</string>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<string>alfred.workflow.trigger.external</string>
<key>uid</key>
<string>8956B5DB-42F0-4570-9265-ECD302239D56</string>
<string>AEE6452E-9186-4609-8AD4-D74F469F1A79</string>
<key>version</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -1060,15 +1027,48 @@ test -n "$bibliography" &amp;&amp; flags+=(--bibliography)
<dict>
<key>config</key>
<dict>
<key>triggerid</key>
<string>copy-citation</string>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>./zh citations "$id" "$1"
</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string></string>
<key>type</key>
<integer>5</integer>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.trigger.external</string>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>AEE6452E-9186-4609-8AD4-D74F469F1A79</string>
<string>8956B5DB-42F0-4570-9265-ECD302239D56</string>
<key>version</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -1158,16 +1158,13 @@ variables={allvars}
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>/usr/libexec/PlistBuddy -c "Set :variables:$varname \"$varval\"" info.plist
# Give Alfred a bit of time to notice info.plist has changed
# sleep 2</string>
<string>./zh setvar "$varname" "$varval"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>5</integer>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
Expand Down Expand Up @@ -1278,7 +1275,7 @@ test -n "$style" &amp;&amp; {
flags+=(--style "$style")
}
./zh select $flags "$1"
./zh style $flags "$1"
</string>
<key>scriptargtype</key>
<integer>1</integer>
Expand Down Expand Up @@ -1308,7 +1305,7 @@ test -n "$style" &amp;&amp; {
<key>passinputasargument</key>
<false/>
<key>passvariables</key>
<true/>
<false/>
<key>workflowbundleid</key>
<string>self</string>
</dict>
Expand Down Expand Up @@ -2140,7 +2137,7 @@ Edit the `ZOTERO_DIR` variable to point to Zotero 5's data directory if you aren
<string></string>
</dict>
<key>version</key>
<string>0.4</string>
<string>1.0</string>
<key>webaddress</key>
<string>https://github.com/deanishe/zothero</string>
</dict>
Expand Down
43 changes: 28 additions & 15 deletions src/zh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Usage:
zh notify [--title <msg>] [--text <msg>]
zh reindex
zh search <query>
zh select [--style <key>] [<query>]
zh style [--style <key>] [<query>]
zh setvar <key> <value>
zh --help
Options:
Expand Down Expand Up @@ -386,7 +387,7 @@ def do_config(query):

items.append((dict(
title=u'Locale: ' + name,
subtitle=u'↩ to change style',
subtitle=u'↩ to change locale',
valid=True,
icon=icon,
), dict(
Expand Down Expand Up @@ -450,7 +451,7 @@ def do_config(query):
wf.send_feedback()


def do_select(query, style_key):
def do_style(query, style_key):
"""Choose a default style."""
from zothero import app

Expand All @@ -476,11 +477,9 @@ def do_select(query, style_key):
icon=icon)
it.setvar('varval', s.key)
# For notification
it.setvar('notifytitle', 'Changed Default Style')
it.setvar('notifytext', s.name)
# Alfred doesn't notice changes fast enough, so turn this off
# for the time being
# it.setvar('next', 'config')
# it.setvar('notifytitle', 'Changed Default Style')
# it.setvar('notifytext', s.name)
it.setvar('next', 'config')

wf.warn_empty('No Matching Styles', 'Try a different query?')
wf.send_feedback()
Expand Down Expand Up @@ -512,11 +511,9 @@ def do_locale(query):
icon=icon)
it.setvar('varval', l.code)
# For notification
it.setvar('notifytitle', 'Changed Locale')
it.setvar('notifytext', l.name)
# Alfred doesn't notice changes fast enough, so turn this off
# for the time being
# it.setvar('next', 'config')
# it.setvar('notifytitle', 'Changed Locale')
# it.setvar('notifytext', l.name)
it.setvar('next', 'config')

wf.warn_empty('No Matching Locales', 'Try a different query?')
wf.send_feedback()
Expand Down Expand Up @@ -561,6 +558,19 @@ def do_reindex():
app.update_index(force=False)


def do_setvar(key, value):
"""Save a variable to ``info.plist``.
Args:
key (unicode): Name of variable to set.
value (unicode): New value of variable.
"""
from workflow.util import set_config
log.debug('[settings] setting "%s" to "%s" ...', key, value)
set_config(key, value, exportable=True)


def do_notify(title, text):
"""Post a macOS notification.
Expand Down Expand Up @@ -643,8 +653,11 @@ def main(wf):
if args['search']:
return do_search(query)

if args['select']:
return do_select(query, args['--style'])
if args['style']:
return do_style(query, args['--style'])

if args['setvar']:
return do_setvar(args['<key>'], args['<value>'])

raise ValueError('Unknown command')

Expand Down

0 comments on commit 4362a97

Please sign in to comment.