Macro to activate Apple Firewall

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?

Many thanks in advance,

Steve

1 Like

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.

Hey Steve,

Keyboard Maestro doesn’t have a built-in method for doing this.

Google: applescript turn off firewall

When looking for an AppleScripted solution always start your search with ‘AppleScript’.

Another thing to search for would be: osx shell script turn off firewall

Keyboard Maestro can run both AppleScripts and Shell Scripts.

http://hints.macworld.com/comment.php?mode=view&cid=106657
https://discussions.apple.com/thread/5209688?tstart=0
http://hints.macworld.com/article.php?story=20090217124731597

The first one looks most promising, because it avoids brute-forcing the UI using System Events.

I have not tested it though, so no guarantees.

-Chris

1 Like

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.

Hey Peter,

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.

-Chris