How to create custom commands for Mac’s Spotlight

Out of the box doesn't seem to be possible 🙁 BUT! I've found a workaround that works almost as nicely 🎉
There are paid apps out there, but we as developers should do it ourselves 👨🏻‍💻 To learn from it and to feel like a hacker.

💡 Create a bash script

I want to able to go quickly to a site from anywhere on my Mac. Sure that's what bookmarks are for, but you need to focus on Firefox, find the bookmark and click on it. That's just too much 😁

Imagine just typing a command in spotlight and be done with it ✅ The bash script below does exactly that.

  1. Opens Firefox Developer Edition
  2. Goes to the URL
  3. Terminal closes itself (I have configured Terminal to not ask for confirmation when closing with open processes).
#! /bin/bash

open -a Firefox\ Developer\ Edition -g
osascript -e 'tell application "Terminal" to quit'
Code language: JavaScript (javascript)

As you know you can do practically anything with a bash script, so just let loose! It doesn't have to be my browser use case 😎

🤔 Easy find/write syntax

I've created my own syntax for naming the files cXZY.command

In the example below: cdev.command will open my dev blog Dashboard in Firefox.

This syntax might not work for your brain just come up with something unique so Spotlight does not give you the wrong result.

Known issues

If I'm watching a video with VLC and run the command it will open Firefox but it will not focus on that app. I've tried to use activate but doesn't work. Ideas?

osascript -e 'tell application "Firefox\ Developer\ Edition" to activate'Code language: JavaScript (javascript)

🐙 Github

I've created a repo for them:

Leave a Reply

Your email address will not be published. Required fields are marked *