As a software developer, I’m always on the lookout for tools and techniques that can streamline my workflow. One such tool that has become indispensable in my daily routine is Alfred, a productivity application for macOS. For quite a while though I merely used this as an App Launcher. I’ll be honest, I didn’t really get it. I mean, I could just use Spotlight, right? But, people swore by how good it was so I decided to give it a go. I’m glad I did. It’s now a key part of my workflow. Even now though I still feel like I’m only really scratching the surface of what it can do. (I’m not affiliated with Alfred in any way, I just really like the app, must do, as I’m also a powerpack user 🚀👀)
So, What is Alfred?
Alfred is at it’s core, an application launcher. It’s a tool that allows you to quickly launch applications, open files, search the web, and more. It’s similar to Spotlight, but with a few key differences. For one, it’s much faster. It also has a lot more features, such as workflows, snippets, and clipboard history. It’s also highly customizable, allowing you to create your own workflows and themes. By workflows, I mean that you can create your own scripts and integrate them with Alfred. This is where Alfred really shines. It allows you to automate complex tasks and streamline your workflow.
Here, I’ll share my basic workflow of how I use Alfred to manage my projects, and how you can set up a similar system for yourself.
The Script
Here’s a simplified version of the script I use, it’s a combination of bash and AppleScript:
project="$1"
echo "Launching project: $project"
launch_project() {
echo "Running $project..."
cd ~/workspace/$project && code . && make start
}
launch_project_2() {
echo "Running $project..."
cd ~/workspace/$project && code . && make start
}
close_apps_except() {
apps_to_keep_open=("Finder" "Alfred 4" ${@})
echo "Closing all apps except: ${apps_to_keep_open[@]}"
open_apps=$(osascript -e 'tell application "System Events" to get the name of every process whose background only is false')
for app in ${open_apps[@]}; do
if [[ ! " ${apps_to_keep_open[@]} " =~ " ${app} " ]]; then
echo "Closing $app..."
killall "${app}" 2>/dev/null
fi
done
}
open_apps_if_not_open() {
apps_to_open=("$@")
for app in "${apps_to_open[@]}"; do
if ! pgrep -x "$app" > /dev/null; then
echo "Opening $app..."
open -a "$app"
fi
done
}
start_music() {
osascript -e '
tell application "Music"
activate
set shuffle mode to songs
play user playlist "My Playlist"
end tell
'
}
case "$project" in
"project1")
close_apps_except "Slack" "Music"
launch_project
open_apps_if_not_open "Slack" "Music"
start_music
;;
"project2")
close_apps_except "Zoom"
launch_project_2
open_apps_if_not_open "Zoom"
;;
*)
echo "No project found for $project" >&2
exit 1
;;
esac
The script takes a project name as an argument and performs a series of actions based on the project. For example, if I’m working on “project1”, it will close all applications except “Slack” and “Music”, launch the project, open “Slack” and “Music” if they’re not already open (I had to add this I noticed on a cold start it wouldn’t launch these apps), and start playing music.
Integrating with Alfred
To integrate this script with Alfred, follow these steps:
- Save the script in a scripts folder in your home directory. This allows you to run it from the command line if you wish, and also keeps code syntax highlighting when adding new projects, as the Alfred code editor isn’t that great.
- Open Alfred’s preferences and go to the “Workflows” tab.
- Click the ”+” button to create a new workflow.
- Add a “Keyword” input and set the keyword to something like “project”.
- Connect the “Keyword” input to a “Run Script” action.
- In the “Run Script” action, enter bash ~/scripts/your_script.sh “{query}”, replacing “your_script.sh” with the name of your script.
- Save the workflow.
Now, you can launch your projects by activating Alfred (usually with the Cmd+Space shortcut), typing “project” followed by the name of your project, and hitting Enter.
With these kinds of workflows, you can automate a lot of your daily tasks and streamline your workflow. I hope this has given you some ideas of how you can use Alfred to improve your productivity. If you have any questions or suggestions, let me know 🚀💪.