Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.5: Enable and disable the firewall via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Enable and disable the firewall via AppleScript
Authored by: dsanfili on Feb 22, '09 01:25:48PM
Nothing original here, I've simply combined a couple of the previous suggestions. Place this one script, saved as an application, in your script folder and use it to toggle the firewall on or off. If the firewall is ON, it will change its name to "Turn Firewall OFF". If the firewall is OFF, it will change its name to "Turn Firewall ON". (Warning - Do not run this script from within the Script Editor. Save it as an application first and then run it).

I have it set to toggle between "Allow all incoming connections" (OFF) and "Set access for specific services and applications" (ON). If you want in to toggle between "Allow all incoming connections" (OFF) and "Allow only essential services" (ON), change the number "1" in line seven to the number "2".

Here's the script:
tell application "Finder"
  set getValue to (do shell script "defaults read /Library/Preferences/com.apple.alf globalstate")
  if getValue is equal to "0" then
    display dialog " Confirm

Turn Firewall ON ?"
    do shell script "defaults write /Library/Preferences/com.apple.alf globalstate 1"
    set the name of (path to me) to "Turn Firewall OFF"
  else if getValue is not equal to "0" then
    display dialog " Confirm

    Turn Firewall OFF ?"
    do shell script "defaults write /Library/Preferences/com.apple.alf globalstate 0"
    set the name of (path to me) to "Turn Firewall ON"
  end if
end tell


[ Reply to This | # ]