Is Network Computer ON?

I run Applescripts within Microsoft Word that transfer documents between my Mac Pro 2019 and my wife’s iMac 2019 over LAN. But when the iMac is not on, the script hangs up Word for about a minute before it generates an error message.

Please provide me with a script to check to see if her iMac is on before attempting to send/receive files. All help is appreciated!

Interesting question, but I’ve never tried testing remote access on a real-world remote computer. Therefore, the following has not been tested by me. This is just my guess. I myself will be interested to know if this works:

	set remoteComputerIsOn to exists machine "eppc://"
on error number -1728
	set remoteComputerIsOn to false
end try

To check if a server or remote computer is active most people use ping.

Here I ping the localhost, the parameter is count of 5

do shell script "ping -c 5"

If you ping a remote IP of machine that is off…

You will get something like this:

An alternative shell script would be to use the ‘networksetup’ command line tool, to get info about your ethernet connection.
Like this.

set ethernetInfo to do shell script "networksetup -getinfo ethernet"

Which will give you a list of info about the ethernet ports connection.
If their is an ethernet connected system, then you will get a different info list, of which there should be an ‘IP address’, which you can retrieve like this.

set ethernetIPAddress to do shell script "networksetup -getinfo ethernet | grep 'IP address' | awk -F ':' '{print $NF}'"

Not tested, as I have no other system available at present to connect to the ethernet port.

Regards Mark

How do you connect to your wife’s computer? Does it show up in the sidebar when it’s connected (under one of the sharing types, e.g. bonjour, connected servers)? There should be some info that would help determine a simple and reliable method of detection, like a hostname or IP address.

Thank you all for your help. I am in the middle of something. I will try all and report back.

I connect my wife’s computer using ethernet and it does show up in Finder. But I have to open finder each time, scroll down to the Network section to see if she’s logged in.

But I do this a few times a day and it has become annoying. It would be nice for my Applescript/VB macros to not try the operation if her system is OFF.

Guys, thanks again for taking the time to provide solutions. Here’s what I found:

KniazidisR’s solution returned "Can’t get machine “eppc…” error

Mark FX’s solution returned “ethernet is not a recognized network service…” error

Fredrik71 solution which was the simplest worked:

set remoteComputerIsOn to do shell script “ping -c 1”


"PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.423 ms

— ping statistics —
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.423/0.423/0.423/0.000 ms"

As you can see I modified it to ping only once. If remoteComputerIsOn contains “0 packets received” it means my wife’s computer is OFF.

Thank you again everyone!

I jumped the gun! Pinging works in the script editor but not in word. Since it takes about 10-15 seconds for Applescript to return the ping results when the remote system is OFF, I get an error message in Word!

Can I change the routine so the script waits 3" for the ping results then aborts the shell command if nothing returned yet?


Something like this will stop your script if your wife computer is off

	do shell script "ping -c 1 -t 2"
on error the error_message
	set the error_text to "Error: " & ". " & the error_message
	display dialog the error_text buttons {"OK"} default button 1 giving up after 3
	return the error_text
end try

-- This command will not be executed if do shell script return error
display dialog "hello world"

Thank you Fredrik! The addition of the error trapping code did the trick for me. I didn’t even need your dialog box. Here’s the final Applescript which is inside a file called “networking.scpt”:

on IsRemoteComputerON(return_value)
set return_value to do shell script “ping -c 1”
on error the error_message
set the return_value to "Error: " & ". " & the error_message
return the return_value
end try
end IsRemoteComputerON

Here’s the calling VB script function in Microsoft Word:

Function IsRemoteComputerON() As Boolean
Dim return_value As String
return_value = AppleScriptTask(“Networking.scpt”, “IsRemoteComputerON”, return_value)
IsRemoteComputerON = InStr(return_value, “0 packets received”) <> 0
End Function

According to Microsoft rules Networking.scpt must reside in the following folder:
~/Library/Application Scripts/

IsRemoteComputerON() returns True if my wife’s computer is ON. It takes 11 seconds on my system to get a response for the shell operation if her computer is OFF. It takes about a second to get a response if her system is ON.

Thank you again for your help Fredrik!

Great it working for you, I guess you did change to the IP of your wife computer :wink:
I only used that to get a error… so my approach work the way you want.

Maybe if you could run shell script in words it could maybe be faster for you.
But I also include the parameters -t 2 if you look at man ping you could see what that parameter
does. And that will I guess from your 11 second to become less…

-t timeout Specify a timeout, in seconds, before ping exits regardless of how many packets have been received.

It means if you set it to 2 or 3 it will give up after 2 or 3 seconds.
And in return your responds will be faster.

Fredrik, you’re the man! You actually answered my previous question about the timeout! The addition of your timeout switch worked like a charm! The Word VBScript returns and error message after about 2.5" when the remote computer is OFF.

Thanks again for everything!