I wanted to trigger the Night focus mode on my iPhone using an NFC tag, which should have been straightforward, but Apple has left a few things out of Shortcuts for Focus triggers and dates and times to make it more of a challenge.
The first part is easy. Go to the Shortcuts app, switch to automation from the icon at the bottom and click the plus button, then scroll down to NFC tag and select this (this same process applies whatever you want to use to trigger it—it doesn't have to be an NFC tag).
Make sure you select "Run Immediately" instead of the default "Run After Confirmation" and scan the NFC tag, if you are using this as a trigger.
You can then add an action to turn the correct focus mode on, but there is no option for "until morning" (or "until this evening" during the day), only until turned off, an event ends, you leave a location or a specified time. But it should, in theory, be possible to emulate the "until morning" option by specifying a time as 7AM, like so:
This works fine if you trigger it after midnight, but if before, it throws an error, telling you to choose a time that isn't in the past as it always assumes, oddly, that you mean 7AM on the current day.
You could change this to specify tomorrow at 7AM like this:
This will work if you trigger it before midnight, but if after, it will leave you in sleep mode for more than 24 hours unless you turn it off manually.
The answer I found was to combine these in an if
statement with some date formatting tricks I had to look up to change the date to a number, as comparing dates directly doesn't seem to be straightforward in Shortcuts. I did this in a new Shortcut to be triggered by the automation. Here's the sequence:
- Add a
Date
action and set it tocurrent date
. - Add a
Format Date
action to use the output of the previous action and clickShow More
. - Change
Date Format
toCustom
and useHH
as the Format String to pick just the hour (in 24-hour clock format, so 0 to 23) - Add an
If
action and make sureFormatted Date
is selected in the condition. Click on it and chooseNumber
as the Type. You can then chooseis greater than
as the condition and add7
for 7AM (or whatever you like) as the comparison. - Under the
If
, add an action to turn on the Focus modetomorrow at 7am
. - Under
Otherwise
, add an action to turn it on at7am
, i.e. on the current day.
Here's the final shortcut:
Go back to your automation and add as the only action Run Shortcut
...
...then search for this shortcut under whatever name you gave to it.
And that's it! Not as straightforward as I thought it should be, but it works, whatever time of day or night I decide to go to bed.
Top comments (0)