4

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 & 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 & emails to every device & account...

12
  • is the do not disturb in notifications not working for you
    – Ruskes
    Commented Oct 28, 2014 at 20:41
  • DND doesn't know when I'm not in the house, but the wifi does - can't see the phone, I'm out. Cannot see any way to tether those 2 rather obvious pieces of information.
    – Tetsujin
    Commented Oct 28, 2014 at 22:37
  • so you would like for someone to write you a script that does that ?
    – Ruskes
    Commented Oct 28, 2014 at 23:06
  • I'd like for Apple to have figured out it was a reasonable requirement... but if you have a volunteer to write a script [or even actually point me in the right direction & I'll have a go myself]... ;-))
    – Tetsujin
    Commented Oct 28, 2014 at 23:10
  • I did some reading, so do you have the "You can be reached by iMessages under this Phone number?
    – Ruskes
    Commented Oct 28, 2014 at 23:14

3 Answers 3

6
+50

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.

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

  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/osascript</string>
    <string>/Users/your-username/bin/check-iphone-available.scpt</string>
  </array>

  <key>Nice</key>
  <integer>1</integer>

  <key>StartInterval</key>
  <integer>60</integer>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardErrorPath</key>
  <string>/tmp/com.your-username.checkiphone-available.err</string>

  <key>StandardOutPath</key>
  <string>/tmp/com.your-username.checkiphone-available.out</string>
</dict>
</plist>

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.

10
  • Looks nicely comprehensive, thank you. I'll have to check it out later in the week & report back [busy over the next few days] +1 for now.
    – Tetsujin
    Commented Nov 1, 2014 at 12:53
  • I've got the basic structure working... but... I'm seeing 2 potential blocking points - I cannot get arp-scan to find any iDevice on the network, though it finds all the wired hardware. If I can get past this point, I haven't yet been able to test whether setting Available or Away is going to work for iMessages [took me quite some time to figure out you can only access those options if you enable Bonjour, or some other legacy iChat-type protocol]
    – Tetsujin
    Commented Nov 5, 2014 at 14:43
  • I'm trying since I wrote my answer and I found one issue with arp-scan. Once you arrive at home you must use the iPhone (open a website on it for example) before can be discovered. If you are trying arp-scan from the terminal, you must sudo. To test if it works, just switch off the wifi on your phone.
    – jherran
    Commented Nov 5, 2014 at 15:26
  • arp-scan -interface=en1 -l can find all the other devices on the network, just not the iDevices, unless I've very recently been using any of them. If I let the phone sleep, it falls off the list. I tried manually shifting the status to Away in Messages & setting airplane mode on the phone... iMessages still turn up at the compy. My current guess is that I would have to sign out to make it stop.
    – Tetsujin
    Commented Nov 5, 2014 at 15:36
  • Could you please replace /usr/local/bin/arp-scan -l with nmap -sP 192.169.0.0/24? Is other way to scan network that must works. On the ip you must use your own range.
    – jherran
    Commented Nov 5, 2014 at 15:47
3

Second solution. This time based on bluetooth.

Download Bluetooth Proximity Tasker. Sorry mate, but it's $2.99.

Run any AppleScript when a paired bluetooth device goes in and out of range. Adjust the range using signal strength.

Select your BT device and paste this script on In Range Applescript:

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"
                                click menu item "Available"
                        end tell
                    end tell
                end tell
             end tell
        end tell
    end tell
end tell

Replace Available with Away in the script and paste on Out Of Range Applescript.

4
  • have a look at my ramblings over a couple of hours on the chat channel. I gave up eventually, as, even though I got your structure working perfectly using arp -a, the away status set for Bonjour is totally ignored by iMessage :( I thank you so much for your efforts & will +1 this answer too. I can't 'accept' either to award the bonus you deserve, as that would perhaps lead people to believe the solution will still work for iMessage.
    – Tetsujin
    Commented Nov 5, 2014 at 21:14
  • Unless there's some way to script the sign in & sign out...
    – Tetsujin
    Commented Nov 5, 2014 at 21:18
  • Last try. Replace Away with Offline. The script basically navigate through iMessage menus. I tell go to Messages → My Status → Offline and click there. When I did it, it works for my three accounts (jabber, bonjour and messages). And don't mind about reward, I'm using this too, and I'm curious about why isn't working on your/others computers.
    – jherran
    Commented Nov 5, 2014 at 22:22
  • I woke this morning to find it thought I'd been Away all night, though everything was still on. I tried swapping to Offline; that worked... yet iMessages still come through to the Mac. Flipping the phone to airplane for a few mins whilst testing, then back on again then showed I was Available. So, I still have the same 2 problems, unfortunately. 1. Recognition of 'when I'm here' & 2. Actual compliance of iMessage to 'believe' when I'm Offline. It seems we're so near, yet so far. I'm iOS8 & Mavericks, btw, Mac Pro 3,1 [so no BT LE] & in fact BT off for the Mac, if that may be different to you.
    – Tetsujin
    Commented Nov 6, 2014 at 8:10
2

Third solution. For this to work your must have an account in ifttt.com (and ifttt app for iPhone) and also a Dropbox account.

I create a couple of recipes in ifttt, If I'm at home create a file on Dropbox and If I leave home create a file on Dropbox. You will have to modify it with your address.

  • The first one create a file called AtHome in the directory IFTTT/iOS on your Dropbox folder.
  • Second one create a file called Out in the directory IFTTT/iOS on your Dropbox folder.

On both recipes when your iphone enters or leaves and area you defined (your house), create one or another file in your Dropbox.

Then this is easier to tack for both files with this applescritp. The script is looking for files created and if exists, change iMessages accordingly and then delete the file. If none of those files exists it will do nothing, so, iMessages will keep the status until the next file is created.

on FileExists(theFile) -- (String) as Boolean
    tell application "System Events"
        if exists file theFile then
            return true
        else
            return false
        end if
    end tell
end FileExists

set IPHONE to FileExists("/Users/username/Dropbox/IFTTT/iOS/AtHome")
if IPHONE then
    set CHANGESTATUS to true
    do shell script "rm -rf /Users/username/Dropbox/IFTTT/iOS/AtHome"
else
    set CHANGESTATUS to false
end if

if CHANGESTATUS is not equal to true then
    set IPHONE to FileExists("/Users/username/Dropbox/IFTTT/iOS/Out")
    if IPHONE then
        set CHANGESTATUS to true
        set IPHONE to false
        do shell script "rm -rf /Users/username/Dropbox/IFTTT/iOS/Out"
    end if
end if

if CHANGESTATUS then
    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 then
                                    click menu item "Available"
                                else
                                    click menu item "Offline"
                                end if
                            end tell
                        end tell
                    end tell
                end tell
            end tell
        end tell
    end tell
end if

You must change /Users/username/Dropbox/IFTTT/iOS/ to point to your real path.

After this, replace the script of my first answer with this, and should work!

4
  • I'm still not sure it's going to work... Even if I switch the Bonjour status manually, iMessages still arrive at the Mac. I do appreciate the enormous effort you have put into this, but I think we're stuck unless there's some way to auto- sign in & out of iMessage on the Mac.
    – Tetsujin
    Commented Nov 6, 2014 at 17:56
  • That three ways works on yosemite. I am not able to test this on your hardware, so, no problem at all. I'm testing in for myself and sharing the results. By the way, the most accurate form is this last one.
    – jherran
    Commented Nov 6, 2014 at 18:49
  • Ahh... then perhaps light at the end of the tunnel. I'm holding off on Yosemite for a while [my first time ever not being an early-adopter] but I am fully prepared to work back through this when I do update. +1 again for this 3rd solution in some small recognition of your effort. Very much appreciated.
    – Tetsujin
    Commented Nov 6, 2014 at 19:03
  • ah, it appears that I can award the bounty without selecting the answer as 'correct'. I don't want to in any way possibly mislead, as I haven't managed to get it going yet - but the bounty is all yours, with thanks.
    – Tetsujin
    Commented Nov 7, 2014 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .