Applescript - Ottieni informazioni dal comando del terminale

0

Sto creando un piccolo script per consentire modifiche rapide alle impostazioni di rete del mio Mac. Ho funzionato tutto, ma volevo essere in grado di vedere quali sono le impostazioni prima di cambiarle nella prima finestra di dialogo.

Il comando che ottiene questa informazione è "networksetup -getinfo device "

Il risultato è il seguente:

Manual Configuration --This may also say DHCP Configuration--
IP address: 192.168.0.100
Subnet mask: 255.255.255.0
Router: 192.168.0.1
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Ethernet Address: (null)

Come posso ottenere l'indirizzo IP, la Subnet mask e il Router come 3 variabili nel mio script, così posso inviarli all'utente tramite i seguenti prompt?

    
posta Tim Rideyourbike 11.07.2015 - 05:55
fonte

1 risposta

0

Ho montato questo bel frammento di codice, provalo, dovrebbe funzionare bene per la tua applicazione specifica.

set device to "Ethernet"

set getInfo to paragraphs of (do shell script "networksetup -getinfo " & device)
set ipAddress to ((item 2 of getInfo) as string)
set subnetMask to ((item 3 of getInfo) as string)
set router to ((item 4 of getInfo) as string)
-- You could use the output here, and remove the rest of the script, or continue to remove the excess wordage.

set ipAddress to ((characters 13 through -1 of ipAddress) as string)
set subnetMask to ((characters 14 through -1 of subnetMask) as string)
set router to ((characters 9 through -1 of router) as string)
    
risposta data 11.07.2015 - 06:53
fonte

Leggi altre domande sui tag