What if the flags for unix command could be a list, and return the values in a dictionary
with a custom key name. Ps. the return value use colon so I guess that approach could also
be used to filter the values and keys.
My approach would be…
use framework "Foundation"
use scripting additions
set sudoPassword to (display dialog "Type your Sudo password" default answer "")'s text returned
set theFlags to {¬
"-getdate", "-gettime", "-gettimezone", ¬
"-getusingnetworktime", "-getnetworktimeserver", "-getsleep", "-getcomputersleep", ¬
"-getdisplaysleep", "-getharddisksleep", "-getwakeonmodem", "-getwakeonnetworkaccess", ¬
"-getrestartpowerfailure", "-getrestartfreeze", "-getallowpowerbuttontosleepcomputer", ¬
"-getremotelogin", "-getremoteappleevents", " -getcomputername", "-getlocalsubnetname", ¬
"-getstartupdisk", "-liststartupdisks", "-getwaitforstartupafterpowerfailure", ¬
"-getdisablekeyboardwhenenclosurelockisengaged", "-getkernelbootarchitecturesetting"}
set theKeys to {¬
"Date", "Time", "Time zone", ¬
"Uusing Network Time", "Network Time Server", "Sleep", "Computer Sleep", ¬
"Display Sleep", "Harddisk Sleep", "Wake On Modem", "Wake On Network Access", ¬
"Restart Power Failure", "Restart Freeze", "Allow Power Button To Sleep Computer", ¬
"Remote Login", "Remote AppleEvents", " Computer Name", "Local Subnet Name", ¬
"Startupdisk", "List Startupdisks", "Wait For Startup After Power Failure", ¬
"Disable Keyboard When Enclosure Lock is Engaged", "Kernel Boot Architecture Setting"}
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set flagsString to theFlags as text
set AppleScript's text item delimiters to ASTID
set resultString to do shell script "echo " & sudoPassword & " | sudo -S systemsetup " & flagsString
set theValues to items 1 thru -2 of (paragraphs of resultString)
set theDict to current application's NSMutableDictionary's dictionary()
repeat with i from 1 to count theKeys
(theDict's setObject:(item i of theValues) forKey:(item i of theKeys))
end repeat
return theDict as record