Estoy usando la escritura predeterminada para establecer/deshabilitar la opción Bloquear todas las conexiones entrantes del firewall OSX.
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 2
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1
Me di cuenta de que la opción no está configurada si el panel de preferencias está abierto.
¿Hay alguna forma de evitar este comportamiento, posiblemente actualizando la interfaz de usuario del Panel de preferencias después de establecer el nuevo valor?
Depende de si desea seguir con Shell o usar AppleScript. Este script de applescript le da una ventana emergente para la contraseña:
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
En Terminal, se ve desordenado:
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'
Reemplace SomeInteger
con un valor.
Actualizar:
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
pasina
más lejos
pasina
más lejos
pasina
más lejos
display dialog
, ¿puedo sugerir que lo eliminewith administrator privileges
? Muestra una ventana de advertencia con un campo de texto de caracteres ocultos que solicita amablemente la contraseña y canaliza la cadena resultante ensudo defaults write
.pasina
pasina