Skip to content

Commit

Permalink
Alfred 4 compatibility
Browse files Browse the repository at this point in the history
Upgrade to version of Alfred-Workflow that supports Alfred 4.
  • Loading branch information
deanishe committed May 30, 2019
1 parent fb14fa8 commit ed152bf
Show file tree
Hide file tree
Showing 14 changed files with 1,082 additions and 516 deletions.
Binary file removed Fixum-0.8.alfredworkflow
Binary file not shown.
Binary file added Fixum-0.9.alfredworkflow
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Alfred Fixum
============

Fix Alfred 3 Python workflows affected by bugs in [Alfred-Workflow][aw], in particular the [the Sierra background process bug][bug].
Fix Alfred 3/4 Python workflows affected by bugs in [Alfred-Workflow][aw], in particular the [the Sierra background process bug][bug].

In some cases, it can also fix Alfred 3 workflows that don't work in Alfred 4.

Fixum analyses your installed workflows to see if any use an old version of the Alfred-Workflow library. If they do, it can update them with a newer, working version.

Expand Down
17 changes: 16 additions & 1 deletion src/fixum.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from collections import namedtuple
from fnmatch import fnmatch
import json
import os
import plistlib
import shutil
Expand Down Expand Up @@ -60,7 +61,7 @@
# Alfred 3 preferences property list. Contains path to workflow
# directory
ALFRED_PREFS = os.path.expanduser(
'~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences-3.plist')
'~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences.plist')

# Initial values for `settings.json`
DEFAULT_SETTINGS = {}
Expand Down Expand Up @@ -149,6 +150,20 @@ def get_workflow_info(dirpath):

def get_workflow_directory():
"""Return path to Alfred's workflow directory."""
# See if we're running in Alfred first.
bundle = os.getenv('alfred_preferences')
if bundle:
return os.path.join(bundle, 'workflows')

# Alfred 4+ configuration
path = os.path.expanduser('~/Library/Application Support/Alfred/prefs.json')
if os.path.exists(path):
with open(path, 'rb') as fp:
prefs = json.load(fp)

return os.path.join(prefs.get('current', ''), 'workflows')

# Fall back to Alfred 3
# It appears that `syncfolder` may be set but not used
# https://github.com/deanishe/alfred-fixum/issues/8
# So don't trust `syncfolder` and fall back to the default
Expand Down
92 changes: 46 additions & 46 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,23 @@
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<key>lastpathcomponent</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>mode=$1
datadir="$alfred_workflow_data"
cachedir="$alfred_workflow_cache"
blacklist="${datadir}/blacklist.txt"
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
# create data &amp; cache directories, logfile and blacklist
test -d "$cachedir" || mkdir -p "$cachedir"
test -f "$logfile" || touch "$logfile"
test -d "$datadir" || mkdir -p "$datadir"
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
# script actions
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
exit 0</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>5</integer>
<key>onlyshowifquerypopulated</key>
<true/>
<key>removeextension</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Fixum</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<string>alfred.workflow.output.notification</string>
<key>uid</key>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
<key>version</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
Expand Down Expand Up @@ -137,23 +116,44 @@ exit 0</string>
<dict>
<key>config</key>
<dict>
<key>lastpathcomponent</key>
<false/>
<key>onlyshowifquerypopulated</key>
<true/>
<key>removeextension</key>
<key>concurrently</key>
<false/>
<key>text</key>
<string>{query}</string>
<key>title</key>
<string>Fixum</string>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>mode=$1
datadir="$alfred_workflow_data"
cachedir="$alfred_workflow_cache"
blacklist="${datadir}/blacklist.txt"
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
# create data &amp; cache directories, logfile and blacklist
test -d "$cachedir" || mkdir -p "$cachedir"
test -f "$logfile" || touch "$logfile"
test -d "$datadir" || mkdir -p "$datadir"
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
# script actions
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
exit 0</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>5</integer>
</dict>
<key>type</key>
<string>alfred.workflow.output.notification</string>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
<key>version</key>
<integer>1</integer>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
Expand Down Expand Up @@ -185,7 +185,7 @@ It is primarily a workaround to fix bugs that are preventing the workflows from
</dict>
</dict>
<key>version</key>
<string>0.8</string>
<string>0.9</string>
<key>webaddress</key>
<string></string>
</dict>
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 ed152bf

Please sign in to comment.