How to tell Messages "I'm not at home"? I leave my Mac running 24/7, but I'm not always sitting at it.

Is there any way to tell the Mac, or Messages specifically, if my phone isn't on the local wifi subnet, don't take messages, leave them for my iPhone to pick up.

Currently, if for some reason I'm out of iMessage range but capable of receiving SMS, messages never arrive at my phone &amp; are not re-transmitted after failing by the sender, because the system considers that handing them to my Mac is sufficient proof I saw them.

Missing jobs I was offered 6 hours ago, just because I was afk, is not a happy sight to return home to.

One option: log out of Messages on the Mac every time I leave the house...
...I'll never remember.
Edit: Logging out of iMessage on the Mac is considerably more trouble than it's worth. It generates half a dozen messages &amp; emails to every device &amp; account...
First of all, you need homebrew installed on your system. If you haven't, visit http://brew.sh for instructions, or let me know and I will try to guide you.

Then you need to install arp-scan. To do it, open a Terminal and type brew install arp-scan. 

Next step. Save the following script, I called check-iphone-available.scpt, but your can rename if you want.

set IPHONE to do shell script "if /usr/local/bin/arp-scan -l | grep your-iphone-mac; then echo 1; else echo 0; fi" user name "your-username" password "your-password" with administrator privileges
tell application "System Events"
    tell process "Messages"
        tell menu bar 1
            tell menu bar item "Messages"
                tell menu "Messages"
                    tell menu item "My Status"
                        tell menu "My Status"
                            if IPHONE is not equal to "0" then
                                click menu item "Available"
                            else
                                click menu item "Away"
                            end if
                        end tell
                    end tell
                end tell
             end tell
        end tell
    end tell
end tell


Replace your-username, your-password and your-iphone-mac. 


your-username must be an administrator user that can sudo on your computer.
your-password password for that user.
your-iphone-mac can be obtained on your iphone, go to Settings -> General -> About and copy Wi-Fi Address.


Give permissions: chmod 775 check-iphone-available.scpt.

The script execute as administrator the command arp-scan. This command sends  ARP  packets  to  hosts on the local network and displays any responses that are received. The grep command look for your iphone on the answer receive by arp-scan. If the iphone is found, then return 1, otherwise, return 0. On 1, the script do click on Available menu item in Messages, on 0, the same on Away (can be changed by Offline, On the phone, etc).

So, let's do it automatically.

Go to folder /Users/your-username/Library/LaunchAgents and save there the following plist file. I named it com.username.checkiphone.plist, but again, feel free to change it.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
  &lt;key&gt;Label&lt;/key&gt;
  &lt;string&gt;com.your-username.checkiphone&lt;/string&gt;

  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
    &lt;string&gt;/Users/your-username/bin/check-iphone-available.scpt&lt;/string&gt;
  &lt;/array&gt;

  &lt;key&gt;Nice&lt;/key&gt;
  &lt;integer&gt;1&lt;/integer&gt;

  &lt;key&gt;StartInterval&lt;/key&gt;
  &lt;integer&gt;60&lt;/integer&gt;

  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;

  &lt;key&gt;StandardErrorPath&lt;/key&gt;
  &lt;string&gt;/tmp/com.your-username.checkiphone-available.err&lt;/string&gt;

  &lt;key&gt;StandardOutPath&lt;/key&gt;
  &lt;string&gt;/tmp/com.your-username.checkiphone-available.out&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


The file is pretty self-explanatory. We will launch the command /usr/bin/osascript /Users/your-username/bin/check-iphone-available.scpt every 60 seconds, will be launched at load, will save errors on /tmp/com.username.checkiphone-available.err and logs on /tmp/com.username.checkiphone-available.out.

Again, replace your-username appropriately.

Last step, tell the Mac launchd daemon to load it.

launchctl load com.your-username.checkiphone.plist


To stop the script, just replace the word load with unload in the above sentence. When your restart your computer the script will be load again. To prevent it, move it to another folder.