Alfred - Dose for Amphetamine

Welcome to this documentation page for Dose - an Amphetamine workflow for Alfred, a menu bar application for macOS that allows you to keep your Mac awake.

What is Dose?

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

Dose is an Alfred workflow that allows you to apply some basic control of Amphetamine from Alfred. You can set your Mac to stay awake indefinitely, for a fixed number of hours or minutes, or until a particular time is reached (up to a day). Similarly you can also trigger it to stay off.

Download Dose

Prerequisites:

Functionality

Dose provides three sets of triggers for functionality, with all of the interactive ones sharing the same trigger keyword of dose.

An external function call is also included, along with some remote access options.

Enable Stay Awake: On/Off

Keyword Trigger: dose

The following will instruct Amphetamine to set the Mac to stay awake indefinitely.

  • dose on
  • dose start

The following will instruct Amphetamine to set the Mac not to stay awake.

  • dose off
  • dose stop

Enable Stay Awake: For

Keyword Trigger: dose By including numeric values and markers for hours (“h”, “hours”, “hour”, “hrs”, “hr”) or minutes (“m”, “minutes”, “minute”, “min”, “mins”), with or without spaces between the value and the marker, Amphetamine will be instructed to set the Mac to stay awake for the specified number of hours or minutes.

The following will all set the Mac to stay awake for a half hour.

  • dose 30m
  • dose 30 m
  • dose 30mins
  • dose 30 mins
  • dose 30min
  • dose 30 min
  • dose 30minutes
  • dose 30 minutes
  • dose 30minute
  • dose 30 minute

The following will all set the Mac to stay awake for an hour.

  • dose 1h
  • dose 1 h
  • dose 1 hour
  • dose 1 hours
  • dose 1 hr
  • dose 1hrs
  • dose 60 mins

To set a Mac to stay awake for an amount of time that is not equal to an hour, minutes must be used, so to set a Mac to stay awake for an hour and a half, this would have to be expressed as 90 minutes and not 1.5 hours. For example:

  • dose 90m

This limitation is because only integer values are accepted by Amphetamine.

Enable Stay Awake: Until

Keyword Trigger: dose By including a time in 24-hour clock format (hh:mm), Amphetamine will be instructed to set the Mac to stay awake until that time next occurs. This does not include a date part, so it has a maximum limit of 24 hours.

The following will set the Mac to stay away until 8:45 AM.

  • dose 08:45

The following will set the Mac to stay away until 8:45 PM.

  • dose 20:45

Amphetamine only deals in hours and minutes. This means that only hours and minutes for the clock format are accepted.

Because Amphetamine only deals with elapsed time, it is worth noting that the precise off time will be measured from the precise trigger time.

Here are some examples to illustrate this.

Trigger Date/Time Command Difference in Minutes Off Date/Time
30 September at 19:01:30 dose 19:02 1 30 September at 19:02:30
30 September at 19:01:30 dose 19:20 19 30 September at 19:20:30
30 September at 19:01:30 dose 18:20 1399 1 October at 18:20:30
30 September at 19:01:30 dose 19:01 1440 1 October at 19:01:30

External Call

External Trigger: call_dose An external trigger is also included to allow you to call this functionality from other Alfred workflows or from other applications. In effect this works the same as the dose keyword.

For example, with AppleScript, you can could set a fifteen minute stay awake instruction with the following code.

tell application id "com.runningwithcrayons.Alfred"
	run trigger "call_dose" in workflow "com.thoughtasylum.dose" with argument "15m"
end tell

Alfred version 5 introduced a URL handler, and you can make an equivalent call with the following url.

alfred://runtrigger/com.thoughtasylum.dose/call_dose/?argument=15m

Enable Stay Awake: Remote Presets

Several remote triggers have been included. These can be displayed in the Alfred mobile app allowing you to remotely keep awake or cancel a wake instruction. The included options are:

Remote Result
Dose On Instruct Amphetamine to keep awake indefinitely
Dose Off Instruct Amphetamine to end any previous keep awake instruction
Dose 30m Instruct Amphetamine to keep awake for 30 minutes
Dose 1h Instruct Amphetamine to keep awake for 1 hour
Dose 2h Instruct Amphetamine to keep awake for 2 hours

If you want to create your own remote pages, you should create your own workflow, and have the pages you add call the external call trigger described above using Alfred’s built in Call External Trigger action, with the following settings.

Setting Value
Workflow ID com.thoughtasylum.dose
Trigger ID call_dose
Passthough: Pass input as argument Checked
Passthough: Pass variables Unchecked

The input to the call shoudl be the instruction for the dose command.

Change Log

  • Version 1.1.1: 2022-10-16
    • FIX: Modified AppleScript for more robust time string formatting.
  • Version 1.1.0: 2022-10-09
    • Add: Support for keep awake until.
    • Doc: New documentation page.
  • Version 1.0.0: 2021-04-22
    • Add: Initial release, everything is new.

Dose is just one of several Alfred workflows I have created. You can find more workflows and blog posts related to Alfred on my Alfred page