Check if Internet Sharing is enabled

Hello all,

I am trying to set up KM to test if Internet Sharing is turned on, and if it isn't to enable it. I've found a script that turns Internet Sharing on, but I can't find any way to get the status of IS without launching System Preferences.

I only want to launch System Preferences if IS needs to be turned on, Is this possible?

/usr/libexec/PlistBuddy -c "Print :NAT:Enabled" /Library/Preferences/SystemConfiguration/com.apple.nat.plist
  • Will return 0 if Internet Sharing is off
  • Will return 1 if Internet Sharing is on

However if Internet Sharing has never been enabled, you won’t get either result, but will instead get an error message.

Since you are looking for “Is It On or Not?” then you can basically just look for a result of 1 because if you get the error message, then it was not configured, so therefore it’s obviously/logically not enabled.

I’ve made a basic macro which runs a script and returns “success” if Internet Sharing is ON. It uses an ‘Else’ to check, and the only actions are a notification telling you which condition is currently active.

You can then edit the macro to your liking.
Test Internet Sharing ON or OFF.kmmacros (3.4 KB)

HTH. Let me know if you have any questions.

Thank you!