Skip to content

Commit

Permalink
Update for Alfred 4
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jul 13, 2019
1 parent ce70735 commit 3837e17
Show file tree
Hide file tree
Showing 12 changed files with 1,018 additions and 509 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ Comes with a bunch of useful generators (recipes) built in, and you can easily a
</dict>
</dict>
<key>version</key>
<string>2.1.2</string>
<string>2.1.3</string>
<key>webaddress</key>
<string>https://github.com/deanishe/alfred-pwgen</string>
</dict>
Expand Down
37 changes: 5 additions & 32 deletions src/pwgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

import logging
import os
import subprocess
import sys

from docopt import docopt
from workflow import Workflow3
from workflow.util import run_trigger

from generators import get_generators, ENTROPY_PER_LEVEL, import_generators

Expand Down Expand Up @@ -102,32 +102,6 @@

HELP_URL = 'https://github.com/deanishe/alfred-pwgen#alfred-password-generator'

# AppleScript to call Alfred
ALFRED_AS = """\
tell application "Alfred 3"
{0}
end tell
"""


def call_alfred_search(query):
"""Call Alfred with ``query``."""
command = 'search "{0}"'.format(query)
cmd = [b'/usr/bin/osascript', b'-e',
ALFRED_AS.format(command).encode('utf-8')]
subprocess.call(cmd)


def call_external_trigger(name, arg=None):
"""Call External Trigger ``name`` with optional ``arg``."""
command = 'run trigger "{0}" in workflow "{1}"'.format(name, wf.bundleid)
if arg is not None:
command += ' with argument "{0}"'.format(arg)

cmd = [b'/usr/bin/osascript', b'-e',
ALFRED_AS.format(command).encode('utf-8')]
subprocess.call(cmd)


def pw_strength_meter(entropy):
"""Return 'graphical' bar of password strength."""
Expand Down Expand Up @@ -515,13 +489,13 @@ def do_set(self):
key = args.get('<key>')
value = args.get('<value>')
if not value:
return call_external_trigger(key, '')
return run_trigger(key, arg='')

if not value.isdigit():
msg = '`{0}` is not a number'.format(value)
log.critical(msg)
print('ERROR : {0}'.format(msg))
call_alfred_search(KEYWORD_CONF + ' ')
run_trigger('conf')
return 1

value = int(value)
Expand All @@ -533,7 +507,6 @@ def do_set(self):
wf.settings['pw_length'] = value
print('Set default password length to {0}'.format(value))

# call_alfred_search(KEYWORD_CONF + ' ')
return 0

def do_toggle(self):
Expand Down Expand Up @@ -593,8 +566,8 @@ def do_toggle(self):
wf.settings['generators'] = active_generators

print("Turned generator '{0}' {1}".format(gen.name, mode))
# call_alfred_search(KEYWORD_CONF + ' ')
call_external_trigger('conf')

run_trigger('conf')
return 0


Expand Down
2 changes: 1 addition & 1 deletion src/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
__version__ = open(os.path.join(os.path.dirname(__file__), 'version')).read()
__author__ = 'Dean Jackson'
__licence__ = 'MIT'
__copyright__ = 'Copyright 2014-2017 Dean Jackson'
__copyright__ = 'Copyright 2014-2019 Dean Jackson'

__all__ = [
'Variables',
Expand Down
4 changes: 2 additions & 2 deletions src/workflow/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# Created on 2014-04-06
#

"""
This module provides an API to run commands in background processes.
"""This module provides an API to run commands in background processes.
Combine with the :ref:`caching API <caching-data>` to work from cached data
while you fetch fresh data in the background.
Expand Down
9 changes: 5 additions & 4 deletions src/workflow/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# TODO: Exclude this module from test and code coverage in py2.6

"""
Post notifications via the macOS Notification Center. This feature
is only available on Mountain Lion (10.8) and later. It will
silently fail on older systems.
Post notifications via the macOS Notification Center.
This feature is only available on Mountain Lion (10.8) and later.
It will silently fail on older systems.
The main API is a single function, :func:`~workflow.notify.notify`.
Expand Down Expand Up @@ -198,7 +199,7 @@ def notify(title='', text='', sound=None):
env = os.environ.copy()
enc = 'utf-8'
env['NOTIFY_TITLE'] = title.encode(enc)
env['NOTIFY_MESSAGE'] = text.encode(enc)
env['NOTIFY_MESSAGE'] = text.encode(enc)
env['NOTIFY_SOUND'] = sound.encode(enc)
cmd = [n]
retcode = subprocess.call(cmd, env=env)
Expand Down
Loading

0 comments on commit 3837e17

Please sign in to comment.