Pannello Preferenze di aggiornamento dopo aver usato la scrittura predefinita

2

Sto usando la scrittura predefinita per impostare / annullare l'opzione Blocca tutte le connessioni in entrata 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

Mi sono reso conto che l'opzione non è impostata se il pannello delle preferenze è aperto.
C'è un modo per evitare questo comportamento, magari aggiornando l'interfaccia utente del Pannello delle preferenze dopo aver impostato il nuovo valore?

    
posta pasine 11.05.2015 - 15:20
fonte

1 risposta

1

Dipende se vuoi restare con la shell, o usare il applescript. Questo script di applescript ti offre un popup per la password:

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

Nel terminale, sembra disordinato:

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'

Sostituisci SomeInteger con un valore.

Aggiornamento:

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
    
risposta data 11.05.2015 - 17:11
fonte

Leggi altre domande sui tag