Skip to main content

Alfred

Alfred is a powerful launcher that you can program to show anything you want. It saved me a lot of time as I use it to search through anything instantly.

It has a great community and amazing workflows that you can use.

I wrote an article on how anyone can start developing workflows of their own using Go language and AwGo library.

Raycast & Script Kit are nice alternatives.

Workflows I use

My most used workflows at current time are:

Coupled with many small workflows I made. I hope to add more workflows of my own to the mix with time.

Alfred theme

I most often use Mono Dim theme when in macOS dark appearance.

I use Mono Light theme with macOS light appearance (when light is hitting the screen).

I also made Mono theme but stopped using it.

The themes work best with GitHub VSCode & iTerm dim themes.

Snippets

I use Alfred together with Keyboard Maestro to automate text expansions. Alfred for simple expansions, KM for complex or per app expansions.

It is a great idea to symlink workflows you are working on so you can work on them in the comfort of your file system and not inside Alfred UUID named directories.

I use this script to achieve this. In example of this workflow you can use it as follows. Assuming the workflow directory contains Alfred workflow contents (info.plist file). You can run workflow-install.py -s workflow.

I can also then use this script and build my workflow with workflow-build.py -v source.

Notes

  • Package workflows from CLI with version numbers
  • Alfred can preserve a user's Hotkey shortcuts, keywords and workflow variable values. Everything else in the workflow directory gets overwritten.
  • I prefix my own workflows that I have not published out to the world with a. prefix. This way I know off hand that this workflow is either private or unreleased yet.
  • Sometimes when passing things from one object into another, you want to clear your {query} being passed to get a clean prompt. To achieve this you can set argument utility and set it as empty like here:

  • You can exclude certain folders or files from being searched. For example, if you have a file filter that searches through some folders and its contents but you don't wish for it to search some big node_modules folder. You can simply add this folder to Spotlight preferences under privacy tab like here:

Code

Strip title and subtext from input. Put inside JSON utility. Useful to get clean prompts in Alfred (i.e. it's used in web-searches workflow)

{
"alfredworkflow": {
"arg": "{query}",
"config": {
"title": "",
"runningsubtext": "",
"subtext": ""
},
"variables": {}
}
}

Export workflow to a location with version number in clipboard.

readonly workflow_dir="{query}"

if [[ ! "${workflow_dir}" == *'Alfred.alfredpreferences/workflows/user.workflow.'* ]]
then
echo "You need to be inside the workflow’s directory in Alfred’s preferences directory." >&2
exit 1
fi

readonly workflow_name="$(/usr/libexec/PlistBuddy -c 'print name' "${workflow_dir}/info.plist")"
readonly workflow_version="$(/usr/libexec/PlistBuddy -c 'print version' "${workflow_dir}/info.plist")"
readonly workflow_file="${HOME}/Desktop/${workflow_name}-${workflow_version}.alfredworkflow"

find "${workflow_dir}" -iname '.DS_Store' -delete

if /usr/libexec/PlistBuddy -c 'Print variablesdontexport' "${workflow_dir}/info.plist" &> /dev/null
then
readonly workflow_dir_to_package="$(mktemp -d)"
cp -R "${workflow_dir}/"* "${workflow_dir_to_package}"
readonly tmp_info_plist="${workflow_dir_to_package}/info.plist"
/usr/libexec/PlistBuddy -c 'print variablesdontexport' "${tmp_info_plist}" | grep ' ' | sed -E 's/ {4}//' | xargs -I {} /usr/libexec/PlistBuddy -c "set variables:'{}' ''" "${tmp_info_plist}"
else
readonly workflow_dir_to_package="${workflow_dir}"
fi

if ditto -ck "${workflow_dir_to_package}" "${workflow_file}"
then
echo "Created ${workflow_file}"
exit 0
else
echo "There was and error creating ${workflow_file}"
exit 1
fi