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 https://ricard.dev/wp-admin/ 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: https://github.com/quicoto/shortcut-commands

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*