Alfred Workflow - Amphetamine App

Recently I’ve been working on smartening up some of my personal workflows for Alfred, the launcher application for macOS. I’ve been a long time user of Alfred and while I created a popular workflow for working with Evernote back in it’s early days, I’ve not posted something about Alfred for the best part of a decade. This seems ridiculous to me given how often I use it and how embedded it is in so much of the way I work on my Mac.

The time is long overdue to put change that and I have several workflows to share in the not too distant future. Today, I’ll be starting off with one of my simpler workflows, but one that I use regularly. It is one to control the Mac app known as Amphetamine.

What is the Amphetamine App?

Have you ever needed to keep your Mac on, when you normally have it sleep or at least turn off the screen? I find myself in this position quite frequently. I like to be responsible and conserve energy where I can, but sometimes I do just need my Macbook Pro to stay on and display stuff. For those occasions I use an app called Amphetamine.

Previously I had used the Caffeine app, and the caffeinate command line utility, but when Amphetamine appeared on the scene it had enough automation control that I could get the best of both worlds and have them reflect one another through the GUI and via a script, and so I transitioned across.

Access

Amphetamine is normally accessed through an icon in the menu bar and a set of menu options, but I found there were several actions I would want to do more than others, and as a frequent user of tools like Alfred, Keyboard Maestro and Better Touch Tool, it seemed sensible to overlay something on top of Amphetamine’s functionality to give me the sort of access and control that would suit my personal needs. Also, these apps also gave me ways to remotely access and trigger automations from my iPhone, which is something that I found I would occasionally want to do.

Workflow: Dose

I’ve named the workflow “Dose”, as it controls what Amphetamine functionality to apply, and it looks like this:

Download Dose

For more Alfred workflows, take a look at the downloadable workflow list on the Alfred project page.

About Dose

The following description is included in the Workflow.

Amphetamine is a Mac app that can be used to stop your Mac from sleeping for a period of time (or indefinitely as long as it has power).

This workflow allows you to apply some basic control of Amphetamine from Alfred. You can set the Mac to stay awake indefinitely or for a fixed number of hours or minutes. Similarly you can also trigger it to stay off.

A number of presets are also included for use with the Alfred Remote app.

Examples
Enable stay awake:

  • dose on
  • dose start

Disable stay awake:

  • dose off
  • dose stop

Enable stay awake for various times:

  • dose 5m
  • dose 10 m
  • dose 90mins
  • dose 1h
  • dose 2hours
  • dose 3hrs

Notes

  1. Spaces can be included between numbers and scale specifiers.
  2. There are multiple ways to specify on/off/time values.
  3. Non-integer (whole numbers) of minutes and hours are not valid.

Dose Highlights

From the above information, hopefully you have the gist of how the workflow works. The dose keyword accepts a range of parameters either Boolean, to enable or disable the stay awake functionality, or time-based, to enable the stay awake functionality for a specific period of time. Enabling and disabling can be enabled with start/stop/on/off, and time can be a positive integer specified in a single unit of time (hours or minutes, not both), expressed with a variety of abbreviations.

As well as the dose keyword trigger, there are several other triggers. The five shown in blue in the workflow screenshot above are remote triggers. These can be added to remote pages in the Alfred remote app for iPhone and iPad. It allows me to remotely trigger particular actions dose actions (on/off/30m/1h/2h) with just a tap of an icon in the app. Something I found very handy if I was called away from my desk for example and wanted to action something, but was unable to quickly return to my desk to do it.

There is also an external trigger, which, amongst other options, allows you to call this functionality from your own Alfred workflow.

As an example, you could set up some hot keys to turn the stay awake functionality on/off, or add an additional remote trigger (here for 15 minutes).

Why would you want to do this rather than just add them directly into the workflow? Well, while Alfred’s workflow migration option allows you to retain some trigger chnages, if I update the workflow and you replace your existing one, you will either lose your additions, or have to copy them across first and set everything up again. By using the external call, you get to keep your additional triggers separate and protected while still being able to update with relative impunity.

Conclusion

This workflow I think is quite interesting as it shows off quite a broad range of inbuilt workflow functionality available in Alfred. From a variety of triggers, to variable transformations, conditional routing, and scripting. I also find it covers a broad enough range of control cases while still allowing me to do things like check the Amphetamine menu bar item later to see how long might be left on a timed session for example.

I hope that you will find this workflow useful too.

Author: Stephen Millard
Tags: | alfred |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read