Skip to content

Instantly share code, notes, and snippets.

@Phuket2 Phuket2/

Created Aug 24, 2018
What would you like to do?
Launch Application - For Alfred Workflow
Launch Application (Emulate standard Alfred operation)
+ Requires Alfred Powerpack and Version 3+
A script meant to be used in Alfred Script Filter(Input) within
a workflow that is connected to a 'Open File' (Action)
looks for entries with ext '.app' in the directories in the _dir_list.
Creates a list of dicts as per the Alfred Documentation and returns
a json string back to Alfred
No recursion is attempted, thats why the list of directories to search.
I looked at doing it recursively, but this did not seem like a great
idea because of older versions, lack of os.scandir in Python 2 etc.
Basically beyond me.
import os
import json
_app_dir = os.path.expanduser('/Applications')
_utility_dir = os.path.join(_app_dir, 'Utilities')
# Directories to look for apps, you can add more dirs to the list,
# they will be searched!
# Dirs added need to be absolute paths
_dir_list = [_app_dir, _utility_dir]
def make_item(file_name, dir_name):
return dict(
subtitle=os.path.join(dir_name, file_name),
arg=os.path.join(dir_name, file_name),
icon=dict(type='fileicon', path=os.path.join(dir_name, file_name)
def make_app_list(dir_list):
app_list = [make_item(fn, d) for d in dir_list for fn in os.listdir(d)
if os.path.splitext(fn)[1] == '.app']
app_list.sort(key=lambda x: x['title'])
return json.dumps(dict(items=app_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.