I want to prevent a certain app from opening if my computer is connected to Ethernet, or in other words, this app should only open if I'm connected to WiFi and Ethernet is disabled. I've got strict requirements at my work with the IT department, and I can't have a certain app opening if I'm connected to the company's internal Ethernet network.
Currently, instead of reaching around the back of my iMac and plugging/unplugging the Ethernet cable manually, I set up KM macros to toggle my WiFi/Ethernet connection by turning off and disabling one, then enabling and turning on the other. Here's a screenshot of what things look like when I'm connected to only Ethernet:
You can see that all other network connections are disabled and greyed out – only Ethernet is enabled and active. When I activate my KM macro to move to WiFi, it looks the same except the WiFi connection is enabled and active, and the Ethernet connection is greyed out and disabled. Sorry, I hope that makes sense and that I'm not annoyingly over-explaining things.
So, again, I'd like to be able to tell KM to prevent a certain app from activating or opening while I'm on Ethernet. Is something like that possible?
You have two choices to prevent the app from launching or activating using a KM Macro:
Disable the Macro (manually or via Action)
Deactivate the Macro Group (by Action) the Macro is in.
Of course this won't stop the App from being manually activated/launched. So you will need a separate Macro that is triggered by either of those events to quit if it happens.
Now, the hard part: How to Detect if your Mac is connected using WiFi. I use this bash script to return "ON" or "OFF":
In case the OP or anyone else is curious of other methods to obtain the Wi-Fi status, here's an AppleScript method:
use application "System Events"
get the description of the ¬
first menu bar item of the ¬
first menu bar of the ¬
application process "SystemUIServer" where ¬
the description contains "Wi-Fi"
--> ➀ "Wi-Fi, No Signal." (On, not connected)
--> ➁ "Wi-Fi, four of four bars, with %SSID%." (Connected)
--> ➂ "Wi-Fi, Wi-Fi is not enabled." (Off)
(the result contains "bars") as integer
--> 1 (connected); 0 (not connected/off)
This, however, only works if you've set the Wi-Fi symbol to be shown in the menu bar (most people do).
You can also use AppleScriptObjC:
use framework "CoreWLAN"
property CWInterface : a reference to current application's CWInterface
set currentInterface to CWInterface's interface()
currentInterface's powerOn() --> true (on); false (off)
currentInterface's ssid() as text --> missing value = disconnected