New Trigger: NFC Tags! (iOS to macOS trigger for KM on a Mac)

I just bought my first NFC tags, which are in the shape of a circular sticker less than an inch in diameter. (They cost about $0.50 each when I bought a pack of 50.) I've successfully used them to trigger a macro on my Mac when I move my iPhone near the tag. It's amazing and exciting. I can hardly wait to see the kinds of things I will be able to do with this. This is a three-clap accomplishment. :clap: :clap: :clap:

Here's how I did it. These are detailed instructions so that most people can copy my method.

Part 1 - Setting up the Shortcut to trigger from the NFC tag

Step 1. Launch Shortcuts in iOS on the device you want to use to trigger the KM macro on your Mac.
Step 2. Open the Automation Tab on Shortcuts.
Step 3. Click on "+" near the upper right corner of your screen.
Step 4. Click on "Create Personal Automation" (because you want this automation to run on your iOS device.)
Step 5. Scroll down to the item that says "NFC" then click on it.
Step 6. Click on SCAN.
Step 7. Move the top of the iPhone within one inch of the tag, until it recognizes the tag.
Step 8. Enter a name for the tag. You may want to name the tag with a word that describes its function. Then click OK. Then click Next.
Step 9. Create your action (see below for an example.) Click Done when done.
Step 10. Click Next.
Step 11. I recommend unselecting the "Ask Before Running" switch on this screen. (If prompted, press Don't Ask.)
Step 12. Click Done.
Step 13. Now test this macro by moving the top of your iPhone to the tag.

For step #9 above, I recommend you first try the simple Example #1 below before trying Example #2.

Example #1 - Triggering a simple (non-KM) shortcut on iOS

Here's an example action for step 9, above: (this one does NOT trigger KM, it's here for demo purposes for beginners)

Step 1. Click on Add Action.
Step 2. Enter the word Weather in the search box. Click on the Get Current Weather icon.
Step 3. Some suggested actions will be listed. Click on "Get Details of Weather Conditions." (If it doesn't appear, search for it.)
Step 4. We want to change the field from "Date" to "Temperature". Click on "Date" to make the change.
Step 5. Click on the suggested action "Text" to add this action. (If it doesn't appear, search for it.)
Step 6. In the text box, type the letters: "Temperature is " then click on the variable labelled "Temperature" in the window below this action. Then click Done.
Step 7. (If needed, close the Weather popup, then) search for the Speak action by entering Speak in the search box.
Step 8. Click on the Speak Text action. You should now have four actions in your list. Return to the first list above.

Example 2 - Triggering a KM macro on your Mac from your iOS device

Step 1. On your iOS device, enter "URL" in the Shortcut search box.
Step 2. Select the OPEN URL action.
Step 3. In the URL action, click on the address box (which by default may say "apple.com")
Step 4. On your Mac now, start the KM Editor, and display your macro that you want to trigger. (For test purposes, try making a macro in KM that speaks the current time, or at least speaks "Hello".)
Step 5. On your Mac, click on "New Trigger" and select "Remote Trigger"
Step 6. On your Mac, click the COPY button that appears near the remote trigger string.
Step 7. Back on you iOS device, your cursor should already be flashing in the URL box. Click in the empty box, then click Paste. The URL address FROM YOUR MAC should appear in the box. If not, try again in a few seconds, because clipboards need to synchronize across iCloud, I think.

WARNINGS

  1. Triggering this macro can sometimes be quick (<1 sec) but can sometimes take a long time (>10 sec). This is probably due to Internet latency. Be patient the first few times.
  2. This macro will leave the "empty" KM trigger website page open in your browser. I can't figured out how to close that yet. I may add that to these instructions when I figure that out.
  3. For iPhones v7 and v8, you may need to download a free app to read the NFC tag. So this works best with iPhones v10, v11, v12 and v13.
  4. This technique does not require that you have unlocked your phone, but it may require that your phone is not in sleep mode. Normally when you pick up your phone the screen comes on since you touch the screen, so this shouldn't be a problem.
  5. This process assumes (for one point in the second example) that you are logged into the same iCloud account on both your Mac and your iOS device. It should still work if they are not synchronized like this, but you will have more difficulty copying the URL from your Mac to your iOS device. I'm going to assume your Mac and iOS devices are synchronized with the same iCloud account, since most people should have this.
  6. I am not yet sure if Apple Watch supports background NFC tag reading. People were asking for this a year ago, but after a minute of googling I haven't seen evidence that Apple has implemented it yet. But I'm not sure.
  7. NFC tags come with small amounts of memory (dozens to hundreds of bytes, I think). For this purpose I don't think memory matters because the only thing we need to store in the tag is its name.

IDEAS for possible use for NFC tags

NON-KM ideas for NFC tags: (although you may be able to enhance these ideas with a KM macro)

  • Make a phone call to someone specific
  • Read the weather forecast aloud
  • Send a text message to someone that you have arrived home
  • Set your smart lights to a dim red colour, and play your favorite song
  • Read out all your calendar events for today
  • Open your shopping list in Reminders
  • Launch a FaceTime call with someone
  • Announce verbally how close you are to achieving your fitness goals for today (eg, walking)
  • Read your current street address aloud (this might be useful when you are in your car looking for an address)

KM ideas for NFC tags:
(not as many as I thought I'd have, but you can help with more ideas, and I may add some of them to this list)

  • Launch a KM macro that shuts down (or puts to sleep?) your Mac
  • Launch a KM macro that logs the date and time when you took your daily medication (assuming you use the Tag to mark when you take your medication. I think I'm going to use this.)
  • Launch a KM macro that starts a Mac backup
  • Launch a KM macro that collects some system information or health checks (eg, uptime, program status/completion) back to your iOS device via an iMessage

If you spot any errors in my instructions above, let me know and I'll correct them.

4 Likes

@Sleepy my 2 main NFC tags are as follows.

I have an NFC tag next to my front door. When I leave the apartment, it triggers a shortcut that turns off my wifi, bluetooth and activates my VPN.

When I return to the apartment, these settings are undone.
This works more reliably than a location-based trigger.

Another one is at my desk. This one activates a Siri shortcut that wakes my Mac from sleep and then does an autofill login.

I don't use the KM Remote/URL trigger. I use SSH Script or a trigger via iCloud Drive when I'm not on wifi.

4 Likes

Thanks for your post and your ideas. I certainly considered that SSH Script, and I did use SSH before (even from my Apple Watch) but for this post I documented only a simpler solution.

1 Like

Maybe I’m just not understanding your post… but your Siri shortcut wakes your Mac or wakes there screen/stops the screensaver?

1 Like

Actually, it wakes your monitor from sleep. Just your monitor, not your Mac. Your macOS is still running. Nothing can run your whole Mac is asleep. (Almost nothing. There is a small clock in most computers, including Macs, that permits you to schedule restarts.)

Actually, you can wake your entire Mac from being turned off using two different ways:

  1. Have your Mac powered by a Smart Plug connected to HomeKit and use an iOS Shortcut to activate the plug. This will turn your Mac back on. (But you will need to have the flag is set up to "start up automatically after a power failure." See second image below. I'm not sure if this flag is on by default because I may have set mine manually.)

  2. Use KM on your Mac to change the wake time of your Mac to a specified time, then use the same Macro to shut the Mac down. While it's possible to use KM to schedule the Mac to restart at a specified time using the following page in System Preferences, (see first image below) there's also a Shell Command that lets you do the same thing. (The Shell command you need to perform this is "pmset schedule".)

I'm not sure which chip in a Mac "stays awake" when the power is out. But something has to be running in order to check the time and decide when to boot up.

One time I set up a recurring KM macro that used "pmset schedule" to schedule a reboot "two minutes in the future." That way if my computer shuts down for any reason, not just a power failure, it will restart in about two minutes.

1 Like

@cdthomer & @Sleepy please excuse the misunderstanding.

Video

This is exactly why I usually make a short video about my macros. My English comes from an online translator.

Using the pushover notification in my macro, it is then possible for me to make a Snapshot via the FaceTime Camera to lock my keyboard and trigger an alarm in case of unauthorized access:

Video

1 Like