Ich verwende die Standard-Schreibfunktion, um die Option „Alle eingehenden Verbindungen blockieren“ der OSX-Firewall zu aktivieren/deaktivieren.
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 2
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1
Mir ist aufgefallen, dass die Option nicht gesetzt ist, wenn das Einstellungsfenster geöffnet ist.
Gibt es eine Möglichkeit, dieses Verhalten zu vermeiden und möglicherweise die Benutzeroberfläche des Einstellungsfelds zu aktualisieren, nachdem der neue Wert festgelegt wurde?
Hängt davon ab, ob Sie bei der Shell bleiben oder Applescript verwenden möchten. Dieses Applescript-Skript gibt Ihnen ein Popup für das Passwort:
do shell script "defaults write /Library/Preferences/com.apple.alf globalstate -int SomeInteger" with administrator privileges
tell application "System Events" to if (first application process whose name is "System Preferences") exists then
tell application "System Preferences"
quit
delay 1
activate
set current pane to pane "com.apple.preference.security"
end tell
tell application process "System Preferences" to tell window 1 to tell tab group 1 to tell radio button "Firewall" to perform action "AXPress"
end if
Im Terminal sieht es chaotisch aus:
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int SomeInteger; osascript -e 'tell application "System Events" to if (first application process whose name is "System Preferences") exists then' -e 'tell application "System Preferences"' -e 'quit' -e 'delay 1' -e 'activate' -e 'set current pane to pane "com.apple.preference.security"' -e 'end tell' -e 'tell application process "System Preferences" to tell window 1 to tell tab group 1 to tell radio button "Firewall" to perform action "AXPress"' -e 'end if'
SomeInteger
Durch einen Wert ersetzen .
Aktualisieren:
set firewallState to do shell script "defaults read /Library/Preferences/com.apple.alf globalstate"
if firewallState is "1" then
tell application "System Events" to display notification with title "Switching Firewall from This to That"
set newState to "2"
end if
if firewallState is "2" then
tell application "System Events" to display notification with title "Switching Firewall from That to This"
set newState to "1"
end if
do shell script ("defaults write /Library/Preferences/com.apple.alf globalstate -int " & newState) with administrator privileges
tell application "System Events" to if (first application process whose name is "System Preferences") exists then
tell application "System Preferences"
quit
delay 1
activate
set current pane to pane "com.apple.preference.security"
end tell
tell application process "System Preferences" to tell window 1 to tell tab group 1 to tell radio button "Firewall" to perform action "AXPress"
end if
Schmerz
weiter weg
Schmerz
weiter weg
Schmerz
weiter weg
display dialog
, darf ich vorschlagen, sie zu löschenwith administrator privileges
? Zeigen Sie ein Warnfenster mit einem Textfeld mit versteckten Zeichen an, das freundlich nach dem Passwort fragt, und leiten Sie die resultierende Zeichenfolge insudo defaults write
.Schmerz
Schmerz