I tried searching this forum for “firewall” but got no results. I hope this isn’t something obvious that I’ve missed.
Is there a way to activate / disable the OS X firewall using an action / macro?
When I’m on my home or office wireless network, i.e. behind my own router, I’d like to disable the firewall. If none of my trusted networks are detected, I want to turn the firewall on. Any thoughts on how to do this?
Generally, with this sort of problem, the best solution is to search the net for whatever you want to do, plus the word “AppleScript”. So for example, search for disable firewall AppleScript. Often it is a good idea to add a time frame, say the last year (or if the problem was a script which broke with the latest OS release, perhaps a month). So search for disable firewall AppleScript; restricted to the last year
Unfortunately, there does not seem to be much in the way of a solution. So its possible the only solution is to use UI scripting to go through the same manual process you would - open the System Preferences, Security & Preferences pane (which there is an action for in Keyboard Maestro), switch to the Firewall setting (which you can do with AppleScript). But then you need to unlock it with your Admin password, and toggle it on or off.
I always stick to using AppleScript in the search because:
It ensures the solution is Mac-specific
If there is a way to do it via shell script, and that is the best way, then the AppleScript folks would use the do script command to solve the problem that way.
This won't always get you where you want to go, although I nearly always start that way - because I'm usually working with AppleScript to begin with.
That’s what the 'osx' leader is for in my 2nd query, although 'Mac OS X' or 'OS X' usually work. The shell-scripting community for OSX is not insignificant, and you can often find very useful things that have no trace of AppleScript related to them.