How To Remotely Control Your Mac Using Simple AppleScripts

applescript1   How To Remotely Control Your Mac Using Simple AppleScriptsIf you’re lucky to have two or more Macs in your home or office, you no doubt find occasions where you would like to remote control a Mac either from another room or from another part of the country. You probably know that you can use the Shared feature to remotely control another Mac on the same network. But by creating some simple AppleScript commands you can control a remote Mac much faster, alleviating the need to open the Shared screen feature.

If you have never worked with AppleScript before, don’t fret. The following Mac remote control scripts are very short and easy to use.

Settings For Remote Control

In order to remotely control a Mac, say your desktop machine, you must first set it up for commands to be sent to it. To do this, launch System Preferences > Sharing on the Mac you want to control. Click the box next to Remote Apple Events, and set user restrictions if you need to.

remoteappleevent   How To Remotely Control Your Mac Using Simple AppleScripts

Next, you will need the IP address. In System Preferences, switch to Network and locate your machine’s IP address. It should be something like, 192.168.2.3.4.. Copy that address to proceed to the next step. You can also use the machine’s Bonjour name which can be found at the top of the Sharing pane in System Preferences. Its address will be spelled similar to this one: “smith-nancy-computer.local.”

Create A Script Command

Now, on another Mac, say your laptop, launch the AppleScript Editor, which can be found in Applications Folder > Utilities Folder. Our first command will be one that puts the remote Mac to sleep.

In AppleScript, go to File > New. Copy and paste the following simple script in the editor:

tell application “Finder” of machine “eppc://192.163.1.2.3″
sleep
end tell

Replace the sample IP address with the address of the Mac you’re going to send the command to. Be sure the address comes after “eppc://.

compilerun   How To Remotely Control Your Mac Using Simple AppleScripts

Now click the Compile icon. If you don’t get an error message, you should be good to go.

authentication1   How To Remotely Control Your Mac Using Simple AppleScripts

Now make sure the remote is awake and running. Click the Run button in AppleScript. You will probably be asked for authentication. Type the username and password of the Mac you’re sending the command to. If it works, then you have successfully sent your first remote command to another Mac.

Saving Your Scripts

There are a couple of ways you can save and access your scripts. You can save them to the Scripts Menu that can be put into the menu bar of your desktop. It looks like this:

scriptmenu   How To Remotely Control Your Mac Using Simple AppleScripts

If it is not there, go to the AppleScript Editor, open its Preferences and click the box, “Show Script menu in menu bar” in the General Pane. If that doesn’t bring it up, look for the AppleScript’s folder in the Applications folder. Inside that folder, find and click on “Install Script Menu.”

scriptsfolder   How To Remotely Control Your Mac Using Simple AppleScripts

Save your script in your Home Library > Scripts folder. It then should show up in you Scripts Menu. From there, you can run the script whenever you need it without having the AppleScript Editor open.

applicationscript   How To Remotely Control Your Mac Using Simple AppleScripts

If you think you’re going to run the script on a regular basis, you can save it as an application and put it in your Dock.

Other Command Scripts

Here are a few other commands that you might want to send to your Mac.

Start iTunes

tell application “iTunes” of machine “eppc://IP Address”
play
end tell

Stop iTunes

tell application “iTunes” of machine “eppc://IP Address”
stop
end tell

Increase Volume

tell application “Finder” of machine “eppc://IP Address”
set volume 7 — Call this one “Full Volume”
end tell

Open The Safari Browser

tell application “Safari” of machine “eppc://IP Address”
activate
end tell

Close The Safari Browser

tell application “Safari” of machine “eppc://IP Address”
quit
end tell

Let me know if this tutorial works out for you. If you know of other AppleScript commands that our readers might find useful, please share them here. For some more AppleScript automation ideas, check out this article, and if you looking for Mac automation tips, download my free MUO Guide to Mac Automation.

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

7 Comments -

0 votes

Nathan Henrie

Even more helpful (for me) has been using Goodreader + Dropbox + Applescript to run scripts from my iPhone. Just use “Folder Actions” (or Hazel) to monitor a folder, using a “if filename matches” cue, and keep a folder of empty .txt files (with appropriate names) sync’d to Goodreader. Upload the files from Goodreader to your monitored Dropbox folder, which will run the script from anywhere.

Make sure to end the script or Hazel action with a “move file to trash” after the applescript is executed.

0 votes

Nathan Henrie

Even more helpful (for me) has been using Goodreader + Dropbox + Applescript to run scripts from my iPhone. Just use “Folder Actions” (or Hazel) to monitor a folder, using a “if filename matches” cue, and keep a folder of empty .txt files (with appropriate names) sync’d to Goodreader. Upload the files from Goodreader to your monitored Dropbox folder, which will run the script from anywhere.

Make sure to end the script or Hazel action with a “move file to trash” after the applescript is executed.

0 votes

Bakari

Great tip. I got all kinds of Hazel workflows. Wish it were a free application, so i could write about it more on MUO.

0 votes

Jeroenvdwel

How can I activate a script on my mac though my iPhone SpringBoard?

Maybe a link that triggers a Folder Actions, but how!!??

0 votes

Jeroenvdwel

How can I activate a script on my mac though my iPhone SpringBoard?

Maybe a link that triggers a Folder Actions, but how!!??

0 votes

Bakari

Jeroenvdwel, I would have to check into that. I don’t use SpringBoard. I use a paid app called Quickeys to activate automations from my iPhone and iPad. I do know that Hazel, also a paid app, is great for folder actions. When a file is dropped into a designated folder (the file could be sent say to a Dropbox folder), Hazel will run a set of rules you apply to it.