Skip to content

Commit ed152bf

Browse files
committed
Alfred 4 compatibility
Upgrade to version of Alfred-Workflow that supports Alfred 4.
1 parent fb14fa8 commit ed152bf

14 files changed

+1082
-516
lines changed

Fixum-0.8.alfredworkflow

-107 KB
Binary file not shown.

Fixum-0.9.alfredworkflow

104 KB
Binary file not shown.

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
Alfred Fixum
66
============
77

8-
Fix Alfred 3 Python workflows affected by bugs in [Alfred-Workflow][aw], in particular the [the Sierra background process bug][bug].
8+
Fix Alfred 3/4 Python workflows affected by bugs in [Alfred-Workflow][aw], in particular the [the Sierra background process bug][bug].
9+
10+
In some cases, it can also fix Alfred 3 workflows that don't work in Alfred 4.
911

1012
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.
1113

src/fixum.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from collections import namedtuple
2929
from fnmatch import fnmatch
30+
import json
3031
import os
3132
import plistlib
3233
import shutil
@@ -60,7 +61,7 @@
6061
# Alfred 3 preferences property list. Contains path to workflow
6162
# directory
6263
ALFRED_PREFS = os.path.expanduser(
63-
'~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences-3.plist')
64+
'~/Library/Preferences/com.runningwithcrayons.Alfred-Preferences.plist')
6465

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

150151
def get_workflow_directory():
151152
"""Return path to Alfred's workflow directory."""
153+
# See if we're running in Alfred first.
154+
bundle = os.getenv('alfred_preferences')
155+
if bundle:
156+
return os.path.join(bundle, 'workflows')
157+
158+
# Alfred 4+ configuration
159+
path = os.path.expanduser('~/Library/Application Support/Alfred/prefs.json')
160+
if os.path.exists(path):
161+
with open(path, 'rb') as fp:
162+
prefs = json.load(fp)
163+
164+
return os.path.join(prefs.get('current', ''), 'workflows')
165+
166+
# Fall back to Alfred 3
152167
# It appears that `syncfolder` may be set but not used
153168
# https://github.com/deanishe/alfred-fixum/issues/8
154169
# So don't trust `syncfolder` and fall back to the default

src/info.plist

+46-46
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,23 @@
4848
<dict>
4949
<key>config</key>
5050
<dict>
51-
<key>concurrently</key>
51+
<key>lastpathcomponent</key>
5252
<false/>
53-
<key>escaping</key>
54-
<integer>102</integer>
55-
<key>script</key>
56-
<string>mode=$1
57-
datadir="$alfred_workflow_data"
58-
cachedir="$alfred_workflow_cache"
59-
blacklist="${datadir}/blacklist.txt"
60-
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
61-
62-
# create data &amp; cache directories, logfile and blacklist
63-
test -d "$cachedir" || mkdir -p "$cachedir"
64-
test -f "$logfile" || touch "$logfile"
65-
66-
test -d "$datadir" || mkdir -p "$datadir"
67-
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
68-
69-
# script actions
70-
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
71-
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
72-
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
73-
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
74-
75-
exit 0</string>
76-
<key>scriptargtype</key>
77-
<integer>1</integer>
78-
<key>scriptfile</key>
79-
<string></string>
80-
<key>type</key>
81-
<integer>5</integer>
53+
<key>onlyshowifquerypopulated</key>
54+
<true/>
55+
<key>removeextension</key>
56+
<false/>
57+
<key>text</key>
58+
<string>{query}</string>
59+
<key>title</key>
60+
<string>Fixum</string>
8261
</dict>
8362
<key>type</key>
84-
<string>alfred.workflow.action.script</string>
63+
<string>alfred.workflow.output.notification</string>
8564
<key>uid</key>
86-
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
65+
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
8766
<key>version</key>
88-
<integer>2</integer>
67+
<integer>1</integer>
8968
</dict>
9069
<dict>
9170
<key>config</key>
@@ -137,23 +116,44 @@ exit 0</string>
137116
<dict>
138117
<key>config</key>
139118
<dict>
140-
<key>lastpathcomponent</key>
141-
<false/>
142-
<key>onlyshowifquerypopulated</key>
143-
<true/>
144-
<key>removeextension</key>
119+
<key>concurrently</key>
145120
<false/>
146-
<key>text</key>
147-
<string>{query}</string>
148-
<key>title</key>
149-
<string>Fixum</string>
121+
<key>escaping</key>
122+
<integer>102</integer>
123+
<key>script</key>
124+
<string>mode=$1
125+
datadir="$alfred_workflow_data"
126+
cachedir="$alfred_workflow_cache"
127+
blacklist="${datadir}/blacklist.txt"
128+
logfile="${cachedir}/net.deanishe.alfred.fixum.log"
129+
130+
# create data &amp; cache directories, logfile and blacklist
131+
test -d "$cachedir" || mkdir -p "$cachedir"
132+
test -f "$logfile" || touch "$logfile"
133+
134+
test -d "$datadir" || mkdir -p "$datadir"
135+
test -f "$blacklist" || cp blacklist.default.txt "$blacklist"
136+
137+
# script actions
138+
[[ "$mode" = dryrun ]] &amp;&amp; /usr/bin/python fixum.py --nothing
139+
[[ "$mode" = fix ]] &amp;&amp; /usr/bin/python fixum.py
140+
[[ "$mode" = blacklist ]] &amp;&amp; open "$blacklist"
141+
[[ "$mode" = log ]] &amp;&amp; open -a Console "$logfile"
142+
143+
exit 0</string>
144+
<key>scriptargtype</key>
145+
<integer>1</integer>
146+
<key>scriptfile</key>
147+
<string></string>
148+
<key>type</key>
149+
<integer>5</integer>
150150
</dict>
151151
<key>type</key>
152-
<string>alfred.workflow.output.notification</string>
152+
<string>alfred.workflow.action.script</string>
153153
<key>uid</key>
154-
<string>90302262-60E4-4C1C-AAEA-2A5C3F4C025A</string>
154+
<string>97033D94-9B6F-446C-94E5-AB677B5ABB4F</string>
155155
<key>version</key>
156-
<integer>1</integer>
156+
<integer>2</integer>
157157
</dict>
158158
</array>
159159
<key>readme</key>
@@ -185,7 +185,7 @@ It is primarily a workaround to fix bugs that are preventing the workflows from
185185
</dict>
186186
</dict>
187187
<key>version</key>
188-
<string>0.8</string>
188+
<string>0.9</string>
189189
<key>webaddress</key>
190190
<string></string>
191191
</dict>

src/workflow/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
__version__ = open(os.path.join(os.path.dirname(__file__), 'version')).read()
6565
__author__ = 'Dean Jackson'
6666
__licence__ = 'MIT'
67-
__copyright__ = 'Copyright 2014-2017 Dean Jackson'
67+
__copyright__ = 'Copyright 2014-2019 Dean Jackson'
6868

6969
__all__ = [
7070
'Variables',

src/workflow/background.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Created on 2014-04-06
99
#
1010

11-
"""
12-
This module provides an API to run commands in background processes.
11+
"""This module provides an API to run commands in background processes.
12+
1313
Combine with the :ref:`caching API <caching-data>` to work from cached data
1414
while you fetch fresh data in the background.
1515

src/workflow/notify.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
# TODO: Exclude this module from test and code coverage in py2.6
1212

1313
"""
14-
Post notifications via the macOS Notification Center. This feature
15-
is only available on Mountain Lion (10.8) and later. It will
16-
silently fail on older systems.
14+
Post notifications via the macOS Notification Center.
15+
16+
This feature is only available on Mountain Lion (10.8) and later.
17+
It will silently fail on older systems.
1718
1819
The main API is a single function, :func:`~workflow.notify.notify`.
1920
@@ -198,7 +199,7 @@ def notify(title='', text='', sound=None):
198199
env = os.environ.copy()
199200
enc = 'utf-8'
200201
env['NOTIFY_TITLE'] = title.encode(enc)
201-
env['NOTIFY_MESSAGE'] = text.encode(enc)
202+
env['NOTIFY_MESSAGE'] = text.encode(enc)
202203
env['NOTIFY_SOUND'] = sound.encode(enc)
203204
cmd = [n]
204205
retcode = subprocess.call(cmd, env=env)

0 commit comments

Comments
 (0)