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

View firewall status via the Scripts menu System
For years, I've been trying to find something that will offer me a quick way to confirm the status of Apple's built-in firewall. It is especially useful to have this functionality if you're running programs that don't play well with firewalls, and you find yourself temporarily turning off the firewall, only to forget to turn it on again later.

Repeated Google'ing confirms that many users are in the same boat. We all want, it seems, something that just sits in the menu bar and monitors firewall status. Why didn't Apple think to include one?! Grumble, gurmble...

Then I had a brainstorm: I figured out a super-quick way to check the firewall status using Terminal (one command, and you don't have to be a Super User to execute it!), so I figured that maybe I could get that to work in conjunction with an AppleScript.

Here's what you do...
  1. Make sure the Script Menu is active -- look in the AppleScript folder (in /Applications) for info on how to enable it. You'll probably want to select Hide Library Scripts from its menu, once it's running.
  2. Open Script Editor (also in the AppleScript folder), and paste in the following code:
    tell application "Finder"
      try
        do shell script 
         "egrep 'true' /Library/Preferences/com.apple.sharing.firewall.plist"
      on error
        set the name of (path to me) to "Firewall is off."
        return
      end try
      set the name of (path to me) to "Firewall is on."
      return
    end tell
    Now just save this as an application (use Save As...), remembering to uncheck the Startup Screen option. The name you save this app under really doesn't matter, as we'll see in a moment.
  3. Put the newly-created application in your user's Library -> Scripts folder. When you click on the script icon in your menu bar, the name will show up. Select it and...
  4. If your firewall is running, the name of the app itself will change to Firewall is on. This is now what will show up when you click on the Script icon on your menu bar. If your firewall isn't running, the name will be Firewall is off.
You can check your firewall status at any time now simply by selecting Firewall is on. or Firewall is off. from the script menu; it will change its name automatically depending on the status of your firewall. For true convenience, however, you can use OS X's cron utility, which is always operating in the background of your system, and which is used to run system tasks on a regular schedule. The easiest way to set a task using cron, I've found, is abstracture's free (donations accepted) CronniX utility.

I have my system set to execute applications named Firewall is on. and Firewall is off. in my user's Library/Scripts folder every five minutes; it simply ignores whichever one is not present. The only thing you have to remember is to put a slash (/) in front of the interval you wish to set. For example, instead of entering 5 for five minutes, enter /5.

This works very well, I've found, with no real demands on the system.

[robg adds: As submitted, this hint instructed the script to be placed in your user's Library -> Preferences -> Scripts folder. I don't believe that's correct, as anything placed there will not show in the Scripts menu. Instead, I've changed the hint to reflect the user's Library/Scripts folder, which does show its contents in the Script menu.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[12,073 views]  

View firewall status via the Scripts menu | 6 comments | Create New Account
Click here to return to the 'View firewall status via the Scripts menu' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View firewall status via the Scripts menu
Authored by: mark hunte on Aug 10, '06 01:53:22PM
Nice idea, but you script does not work for me.

so I modified it.


tell application "Finder"
	try
		set plistPath to "/Library/Preferences/com.apple.sharing.firewall"
		set getValue to (do shell script "defaults  read " & plistPath & "  state")
		if getValue is equal to "0" then
			set the name of (path to me) to "Firewall is (off )"
		else if getValue is equal to "1" then
			set the name of (path to me) to "Firewall is ( on )"
		end if
	on error
		set the name of (path to me) to "Firewall  ( UNKNOWN STATE )" -- just in case
		return
	end try
	return
end tell 

---
mh

[ Reply to This | # ]

View firewall status via the Scripts menu
Authored by: robtain on Aug 10, '06 02:06:20PM

The original script did not work for me either, but Mark Hunte's modified version did. Thanks!

A IMPORTANT CAVEAT: If you run this script from within Script Editor, IT WILL RENAME SCRIPT EDITOR!!! After that, Script Editor will no longer be recognized on your system until you name it back to "Script Editor.app". The ".app" is necessary for the system to recognize the package as an application rather than a folder.

R.



[ Reply to This | # ]
View firewall status via the Scripts menu
Authored by: EddEdmondson on Aug 11, '06 06:52:17AM

You could always try doing the sensible thing and not running as an administrator user unless you actually have to.

I just ran the script and it just popped up an error dialogue. No harm done to the Script Editor application.



[ Reply to This | # ]
View firewall status via the Scripts menu
Authored by: S Barman on Aug 10, '06 07:35:06PM
First of all, DO NOT TEST EITHER SCRIPT IN THE SCRIPT EDITOR! If you do, it will change the name of Script Editor to "Firewall is (off)" or "Firewall is (on)" and you will loose the Script Editor. If you did run this in Script Editor, you need to rename the editor back, from the Terminal:
  1. cd /Applications/AppleScript
  2. mv Firewall* Script\ Editor.app
Second, neither script worked for me. I am using Tiger, fully updated, on a 17-inch PowerBook and have never configured the firewall. I don't use WiFi and I have an external firewall on my home network, so the built-in firewall is of no use to me. However, in both cases, the tests say the firewall is on. I checked with ipfw and verified that it is turned off. Sorry!

[ Reply to This | # ]
View firewall status via the Scripts menu
Authored by: kholburn on Aug 10, '06 10:45:33PM
How about this. It's a bit safer. You might also want to check for the existance of the file:

/Library/Preferences/com.apple.sharing.firewall
as well

tell application "Finder"
	try
		set plistPath to "/Library/Preferences/com.apple.sharing.firewall"
		set getValue to (do shell script "defaults  read " & plistPath & "  state")
		if getValue is equal to "0" then
			my setter("Firewall is ( off )")
		else if getValue is equal to "1" then
			my setter("Firewall is ( on )")
		end if
	on error
		my setter("Firewall ( UNKNOWN STATE )")
		return
	end try
	return
end tell

on setter(mymessage)
	if the name of me contains "Script" or the name of me contains "Editor" then
		display dialog mymessage buttons {"OK"}
	else
		set the name of (path to me) to mymessage
	end if
end setter



[ Reply to This | # ]
The requisite GeekTool addendum
Authored by: klktrk on Aug 11, '06 02:46:23AM

So, if you just want to see the state of your firewall at a glance, use GeekTool.... read on

  1. Click on "New Entry"
  2. Rename the new entry from 'console' to 'Firewall state'
  3. Select Shell from the popup selector at the top of the pane
  4. In the command pane, paste this (all on one line): if [ `defaults read "/Library/Preferences/com.apple.sharing.firewall" state` -eq 1 ];then EX=0;else EX=1;fi;exit $EX
  5. For refresh, enter an appropriate amount of seconds for how often the command should check the state of the firewall. I chose 900 seconds. I can live with it being off for fifteen minutes.
  6. Under the icon tab, select "Show icon", click the default button.
  7. Under the location area at the bottom, select "Always on top"

Now move the green (or red) lozenge icon to wherever you want it to appear on screen. If the firewall is on, you'll have a green lozenge, if the firewall is off, it will be red.

Of course, if you'd rather have a text read out, modify the command like so (again, all on one line): if [ `defaults read "/Library/Preferences/com.apple.sharing.firewall" state` -eq 1 ];then echo "Firewall On";else echo "Firewall Off";fi;

Then skip all the icon stuff and just place the text phrase anywhere on screen you would like to have it.

That was a close call! I was afraid this hint would be without a GeekTool addendum.



[ Reply to This | # ]