configure application to quit based on IP address

Hi Everyone,

I have a strange scripting question…I have an application, called “EuControl”, which runs at login. It relies on an ethernet-connected device for it to work, and when this device is not present, it brings up a dialogue complaining that it can’t find the device. Is there a way to create a script that will either:
a. Run the application when it detects the device’s specific IP address, instead running as login item
or
b. quit the application if the IP address of the device is nonexistant. For script reference, the self-assigned IP address of the device is 169.254.31.224

Thanks so much, please let me know if any of this doesn’t make sense and I will explain further.

Rocco

Hey Rocco,

I expect you could do this with a stay-open script running as either a plain AppleScript applet or a faceless one.

However “ in my opinion this sort of job is better done via an automation utility like Keyboard Maestro.


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Ok, I think Keyboard maestro looks a little complex for something like this…could I use an automater workflow? Or would it be easier at that point to set up an applescript applet? If the ladder is true, how would I script that?
Thanks,

Rocco

Hey Rocco,

Keyboard Maestro has a specific login trigger, so this kind of thing is its bread and butter. Yes “ it might be overkill for just this task, but you’d be surprised how much a few macros can change your computing life. (I have a few hundred.)

I may have misunderstood your original question.

Are you proposing that either (a) or (b) be accomplished ONLY at login?

-Chris

Hi Chris,

Yes, that was my original plan…but now that I’m thinking about it, I’d rather just create an applet that starts “EuControl” (if not already running) when ethernet is connected and has that specific IP, and quits EControl when ethernet does not have that IP Address. How would I go about doing this?

Also, are macros key commands/keyboard shortcuts? I’ve set these types of things up before using automated and services, but that’s not what I’m looking for for this particular situation. :slight_smile:

Does anyone know of a solution to this as described above? :slight_smile:

The best way is to use a launcher, like commands ending with ctl as in systemctl or apachectl. The launcher will be launched at startup and when there is any change to the system configuration in /Library/Preferences/SystemConfiguration folder. The latter can be launched using watchpaths.

The script itself is like this pseudo code and can be written in either bash or AppleScript

[code]set targetip to “999.999.999.999”
if “EuControl” is in listOfRunningApps then

application is running, check if we need to shut it down

if not ping -o -t 1 targetip then
quit application “EuControl”
end if
else

application is not running, check if we can launch it

if ping -o -t 1 targetip then
launch application “EuControl”
end if
end if[/code]
The script will be launched when there are any changes made to the system. In practice it can be launched more time than needed (read: changes to both Airport and Network) but the script won’t change anything unless availability has changed by pinging the required server.

One drawback here is that when the server is down at startup and network is fully initialized, the application won’t be launched until something has changed in the SystemConfiguration folder. Of course this also applies when the server is suddenly down and not your network connection, the application won’t be quited.

Hi, thanks so much, this is great start! However, this particular device doesn’t actually connect to the internet. It uses ethernet asa protocol to transfer data from itself to the computer using a proprietary network, called Eucon. This is why it self-assigns the same IP address every time. That’s also why I want the script to use that specific IP to check if EuControl can be run or not, because if I plug an ethernet cable into my computer that goes to the wall, giving me internet access through ethernet, I don’t want that to effect the script. But because this device doesn’t connect to the internet, I don’t think it could ping a server, like this script suggests. When I try to run the script, it complains that it expected “then” but found “1” in the “ping target” line.

Thanks,

Rocco

:slight_smile: The code I posted was pseudo code, meaning human readable code that isn’t actually code. Here how the script can look like in AppleScript:

set targetip to "999.999.999.999"
if "EuControl" is in getListOfRunningApps() then
	# application is running, check if we need to shut it down
	if not ping(targetip) then
		quit application "EuControl"
	end if
else
	# application is not running, check if we can launch it
	if ping(targetip) then
		launch application "EuControl"
	end if
end if

on ping(IPAddress)
	return (do shell script "ping -o -t 1 " & IPAddress & " &>/dev/null && echo yes || echo no") as boolean
end ping

on getListOfRunningApps()
	tell application "System Events"
		return name of every process
	end tell
end getListOfRunningApps

I see. I tried this script, and it gives no errors, but it doesn’t actually open/close the EuControl application. Could this have something to do with the ping issue I talked about earlier? Also, the EuControl application is inside a folder called Euphonix, inside of the applications folder. Does this need to be specified in the script for it to work?

When speaking of Ethernet and IP addresses there must be some sort of routing. Ping is the easiest way to see if there is a device assigned to an IP address and it doesn’t need to be a server, it can also show you that your routing is not correctly setup. However not every device supports ICMP protocol (which is part of TCP/IP) which can be the reason why you can’t ping the device.

Ok, so is there a way of checking whether this device can be pinged or not? If it can be, can you think of any other reason why the script wouldn’t work properly?
For reference, this is the device i’m talking about:
http://www.avid.com/US/products/artist-mix

any suggestions?..