Control your Mac from your iPhone using Shortcuts

Learn how to securely control your Mac (or any computer) from your iPhone using Shortcuts with SSH. In the end, you can even use Siri to control your Mac.
Pictures from Virul Weerasooriya and Dimitri Karastelev on Unsplash

Did you ever wonder if it was possible to turn on and off your Mac remotely? Or if you could automize any task you do on your computer right from your iPhone? You can do this and much more, it takes no more than 10 minutes to set up, and I am going to show you how.

A cool thing to note:

Since we are using SSH, it means you can control your Mac or Linux based computer from any smartphone or computer. Basically, you can control your computer from any platform with this method!

Don’t feel like reading? I made a TikTok video showing exactly how to do it, feel free to check it out!

At the end of this tutorial you will have a shortcut that can put your Mac to sleep, wake it up and open any application on your computer.

@plassonade

Replying to @John 🖥️ Take control of your Mac with iPhone shortcuts #fyp #techtok #shortcuts #ios #smarthome #apple

♬ Luxury fashion (no vocals) – TimTaj

Preparing your Mac

We first need to allow remote access on your Mac, open System Preferences > Sharing and toggle Remote login. Make sure your user or group of users is selected.

You also need to know your Mac’s IP address. To find it, go into the Wi-Fi settings, tap Details on the network you are connected to and write down your IP.

Then, open your Terminal app (find it in the Applications or use Spotlight) and type this command:

mkdir -p ~/.ssh

This code will, if it doesn’t exist yet, create the necessary ssh directory at the root of your profile directory. We will use it later on.

Finally, for authentication purposes, you need to know your Mac’s username. If you don’t know it yet, on the same terminal, type this command:

whoami

This will return your current Mac username.

Creating the shortcut

Open the Shortcuts app and tap on the + icon to create a shortcut.

Tap on Add Action and search for the Run script over SSH block.

The first text field is the script part. It’s where you will type the command you want your Mac to run. The fields below are related to authentication (except the last “input” field, where you can link this block with another).

Let’s take care of the authentication part:

  • Host → Your Mac’s IP address
  • Port → Leave it as is (22)
  • User → Your Mac’s username

On the authentication part, you have two options: Password or SSH Key. The easiest way is to go for the password option, where you would just need to type your Mac’s user password, it would just work. However, this is also the less secure option. This is why I would recommend you to select the SSH Key option.

NB: To be fully secure, you also need to disable the remote password login on your Mac. We will cover this in a next tutorial.

SSH Key authentication

When you select SSH Key on the Authentication field, an SSH Key field will appear. Tap on the key, a modal will appear, tap on Copy Public Key.

Now, your SSH Key is in your iPhone’s clipboard. If you have Continuity/Handoff activated between your iOS devices, your SSH Key should also be in your Mac’s clipboard. To be sure, paste it in your notes or anywhere. If you don’t have Continuity/Handoff activated, find a way to send it to your Mac and copy the key in order to have it in your Mac’s clipboard. Having the key copied is necessary for the next command.

On your Mac, open a Terminal if it’s not already open and run this command:

pbpaste >> ~/.ssh/authorized_keys

This will paste the content of your Mac’s clipboard (the SSH Key you copied just before) and will paste it in a new file authorized_keys which contains all the SSH Key allowed to access this computer.

To make sure you have your SSH Key copied, you can run this command:

cat ~/.ssh/authorized_keys

Running commands

And now the fun begins.

Let’s first try to open an application on your Mac, on the iOS Shortcut Script field, write this:

open -a Spotify

You can replace Spotify with any application name in your Mac.

Let’s put your Mac to sleep with this command:

pmset sleepnow

We can wake your Mac with this command:

caffeinate -u -t 2

You can now basically create a shortcut for each command or even one shortcut for multiple commands and ask Siri (from a HomePod or your iOS device itself) to run them. For example, “Hey Siri, turn on the iMac“.

Taking it further

You can make your Mac do anything you want, you just need to know the right command to do so.

For example, you could make your Mac say something for you using this command:

say "Welcome back sir, all systems are ready."

And to make sure that it’s loud enough, you could run this command beforehand:

sudo osascript -e "set Volume 10"

0 being mute, 10 is the loudest.

To look for the command you want, you can just go on Google or ChatGPT and query something like: “raise the volume macOS command line”.

Don’t forget to tell me in the comments what are the commands you use!

See you around.