photo credit: PeterThoeny via photopin cc

Improve your workflow with Spotlight and Flashlight

I’m a huge fan of Alfred, but since the recent Yosemite update, Spotlight might just going to change that. You see, the new design and features of Spotlight are already great, but Alfred still proved more functionality, especially with the Power Pack feature to create your own workflows.
But when you combine Spotlight with a little something called Flashlight, magical things happen. All of a sudden you’ve got a hook to create your own plugins that give Spotlight a nice little boost in functionality. So dust off your Python skills and I’ll show you how:

Install Flashlight

Flashlight is a nice little app that – as it states – is the missing plugin system for Spotlight. The first thing you need to do is download and enable it:

Play around with it, enable some plugins that you like and test it out. All done? Great! Then let’s get to the fun part: creating your own plugin.

Create a plugin for Flashlight

Now all these default plugins are great and all, but let us create our own plugin. In this example, I’ll show you a little plugin I created that I use to open JIRA tickets. What I want, is that I type a command in Spotlight, like “jira abc-123” and when I press enter I want to open the corresponding ticket in the browser.

Step 1: create a bundle directory

The first thing you need to do is create a directory for your plugin. Your local plugins are located in ~/Library/FlashlightPlugins . Create a new folder in that directory called jira.bundle .

Step 2: create a info.json file

In this directory, create file called info.json . This file is used by Flashlight to get stuff like a name, description, examples, etc. Important: the name -attribute must represent the name of the directory. So in this example, this must be jira :

Step 3: create an examples.txt file

Also create a file called examples.txt . This file is used by Flashlight to ‘know’ which command in Spotlight should trigger this plugin. We want our plugin to be trigger by either beginning our Spotlight search with “j” or “jira”, and we want to store what’s behind that in a variable called jira_query  (we’ll get to that later):

Step 4: Python it all together

Flashlight uses Python as scripting language to execute your plugin, so lets create a simple Python script. Create a file called plugin.py  and paste the following code:

Let me explain what’s going on here: the first part, def results() , is triggered for the auto complete function of Spotlight. In this example I read the jira_query  parameter from Spotlight and return it in the title:

Screen Shot 2014-11-27 at 08.53.01
The second part, def run() , is triggered when I press enter in Spotlight. In this example it creates a URL with the variable stored in jira_query , so it simply opens the URL https://my-jira-installation.net/browse/abc-123.
That’s it! You’re now ready to give your freshly created plugin a spin!

In conclusion

This is a very simple example of how you can utilize Flashlight and Spotlight to improve your workflow. The plugin is quite simple but it gives you an idea of what’s possible. And since you have Python as a scripting language, the possibilities are enormous.
If you want to learn more about plugin authoring for Flashlight, look at the Github page of Flashlight, or learn from some of the already shipped plugins with Flashlight.

Visitors give this article an average rating of 4.5 out of 5.

How would you rate this article?

Leave a Reply