script to open a firewall rule in System Preferences/Firewall in 10.4.

I like to make a script that would open a firewall rule in System Preferences/Firewall in 10.4.11

I have the following:

do shell script “/usr/bin/open /System/Library/PreferencePanes/SharingPref.prefPane”
activate application “System Preferences”
tell application “System Events”
tell application process “System Preferences”
tell tab group 1 of window “Sharing”
click radio button “Firewall”
click checkbox 1 of row 16 of table 1 of scroll area 1 of tab group 1 of window “Sharing”
delay 5
tell application “System Events”
quit application “System Preferences”
end tell
end tell
end tell
end tell

but it hangs on the line

-click checkbox 1 of row 16 of table 1 of scroll area 1 of tab group 1 of-

I get error: System Events got an error: NSReceiverEvaluationScriptError: 4

As you might have guessed it is the 16th rule in my firewall hence my reference to row 16

Thanking you in advance

Hi,

the firewall tab of System Preferences > Sharing is a GUI for the internal firewall ipfw.
You can set and reset rules with the ipfw shell command
ipfw man page

to determine the rule enable / disable the checkbox and check in terminal.app the differences with

sudo ipfw show

Thanks for you reply Stefan,

I did not know you could check in terminal.

However my Terminal skills are limited for one and I like to do this by using a script. see I have one that sets settings in the sharing window and that works, I jsut do not seem to be able to figure out how to do it in the firewal window.

Two reasons, why the script doesn’t work

¢ wrong (double) referencing


 tell tab group 1 of window "Sharing"
            click radio button "Firewall"
            click checkbox 1 of row 16 of table 1 of scroll area 1 of tab group 1 of window "Sharing"
end tell

references:

checkbox 1 of row 16 of table 1 of scroll area 1 of tab group 1 of window "Sharing" of tab group 1 of window "Sharing"

which of course doesn’t exist

¢ timing problem
you have to wait until the proper UI elements are present.
System Preferences are scriptable, it’s not needed to open the pane with a shell script.
Normally the tab will be selected with the reveal anchor command,
in this special case the Firewall tab is disabled in the moment the window opens, so you have to click the tab


tell application "System Preferences"
    activate
    reveal anchor "Firewall" of pane id "com.apple.preferences.sharing"
end tell

tell application "System Events"
    tell application process "System Preferences"
        tell tab group 1 of window "Sharing"
            click radio button "Firewall"
            repeat until value of static text 2 contains "Firewall"
                delay 0.5
            end repeat
            click checkbox 1 of row 16 of table 1 of scroll area 1
        end tell
    end tell
end tell
quit application "System Preferences"

Note: to quit an application works completely without System Events

PS: GUI scripting is the worst case for me, I prefer every solution to work around GUI scripting, even if it’s pretty complicated :wink:

Stefan thank you.

It sort of works. it indeed ticks the right box in the firewall setting, but it does not hold. that means as soon as you close the control panel it deselects the rule. so it is of again. I tried the script by not quitting the SP/Sharing, but again as soon as you even select the SP it un-ticks the rule.

I am at a loss, and even less skilled at this as you seem to be. Any thoughts?

Hm,

I’ve tested the script successfully on 10.4.11 with enabled and disabled firewall.

That is one of the reasons why I hate GUI scripting :wink:

Mmm, belief you, so what could it be, have tried again and it does not stick.