Alexander / Aebian

Who am I?

Musician, Programmer, Linux Geek and what not.  more...


The Categories



Stuff

Arma CodeList
Legal Things
GitHub Projects
Media (Gallery)
My Hardware
My Wishlist
Player


December 3rd at 3:02pm
Report a website issue
For best viewing experience use a 4k screen.
Sidebar ➠

❬ Back to Blog


Apple Shortcuts & WoL with Apple Watch


Wake your computer from anywhere in the world with Apple Shortcuts and your Apple Watch*

Greetings,

In this post I will show you a simple method of starting your computer from anywehre in the world using your Apple Watch.
*Side-Note: The method probably works with Android or other watches as well, however I don't know a Apple Shortcuts alternative as I don't use Android

For this process we need:

  • a Linux server running with the wakeonlan package
  • a web server of your choice with PHP setup (I use nginx)
  • access to this web-server over the internet

The goal is to run a URL which will start the wakeonlan command to wake the computer(s).

First of we gonna create a php file called WoL.php somewhere browser accessible:

You can create another vhost with own subdomain if you like. This way it is seperated from any other vhost you have. In the script you need to modify a few things:

  • userName (on Line 15) needs to be a username of your choice.
  • codeSection (on Line 15) needs to be a number of your choice. Both can have any length you wish. This is a simple way of allowing the script only to run when specific values are sent along.

    Besides that we have two more items to adjust:
  • computerName (on Line 19) needs to be a name you give, that will identify which computer to start.
  • <M:A:C> (on Line 20) needs to be completely replaced with the actual mac address of the computer in UNIX format

If you want to add more computers you can just copy the case-block and put it before the default-block.
Once you have put into an accessble location you can run the php-fle via your browser: example.com/WoL/WoL.php?u=userName&c=123456789&device=computerName

This will then use the underlying linux server to send a signal via the network to startup the computer mentioned via MAC-address. To fix your WakeOnLan if it is not working you can try https://aebian.org/story/fixing-wakeonlan


Now onto the Apple Shortcuts:

Open the Shortcuts App
AppleShortcuts.png

Select the Plus-Icon at the right and create a new shortcut. Swipe up from the bottom to bring up the categories.

  • Select "Web"
  • Select "Get Contents of URL"

In the URL placeholder fill in your URL example.com/WoL/WoL.php?u=userName&c=123456789&device=computerName
Once done long-press on your shortcut and open the details menu of the shortcut:
AppleShortcutsWatch.png

  • Select "Show on Apple Watch"

Then you can start the shortcut by saying the wake-words defined using "Hey Siri, [...]" or by accessing the shortcuts via the app on your watch.


Q: Why not use the SSH shortcut feature?
A: You would need to expose SSH to the outside world and Apple Watch can't handle SSH afaik. Otherwise the SSH feature can't use your own SSH-keys and creates its own key.
In my case I already had a webserver exposed for other things, so it was the ideal choice.

Q: Can the script run on an external server?
A: Technically yes, but you would need a direct connection to your home network, otherwise the wakeonlan command will never reach the intended target.


Over and Out,

Aebian