2

I'm trying really hard to find a simple way to fetch all network UUIDS on my Mac to be able to do some plist magic.

Is there a command to do such a thing?

If I look in the plist I'll find for an instance "Service Order"

   ServiceOrder = Array {
         2AF2313D-AB7E-4FE7-91C3-XXXXXXXXXXXX
         9B976E4D-F7BE-428D-88C2-YYYYYYYYYYYY
         9A26C39B-8BD4-4562-9E0A-ZZZZZZZZZZZZ

But is there a simpler way than just writing a long script deleting the parts before and after?

All computers running Yosemite.

Final Script - Thanks to @Asmus for providing answers to get this working

#!/bin/sh
# Setting value on "SetUDIDSets" to define the "Sets" name as this will be different on each computer
SetUDIDSets=$(/usr/libexec/PlistBuddy -c "print :Sets" /Library/Preferences/SystemConfiguration/preferences.plist | perl -lne 'print $1 if /^    (\S*) =/')

IFS=$'\n'
    # Loops through the list of network services and sets Exclude Simple Hostnames to 1.
    for i in $(/usr/libexec/PlistBuddy -c "print :Sets:$SetUDIDSets:Network:Global:IPv4:ServiceOrder" /Library/Preferences/SystemConfiguration/preferences.plist | awk 'NR>2{ print l} {l=$0}' | perl -pe 's/^\s+//');
    do

# If the setting Exclude Simple Hostnames never has been touched we need to create this
    sudo /usr/libexec/PlistBuddy -c "add :NetworkServices:$i:Proxies:ExcludeSimpleHostnames integer 1" /Library/Preferences/SystemConfiguration/preferences.plist
    sudo /usr/libexec/PlistBuddy -c "set :NetworkServices:$i:Proxies:ExcludeSimpleHostnames 1" /Library/Preferences/SystemConfiguration/preferences.plist

    echo "Exclude Simple Hostnames is now set for $i" 

    done

unset IFS
defaults read /Library/Preferences/SystemConfiguration/preferences.plist
echo "We're done!"
4
  • Depending on what you want to do in the end, would networksetup -listnetworkserviceorder help? It doesn't return the UUIDs, but prints the information nicely and networksetup is the tool to enable/disable network configurations.
    – Asmus
    Commented Mar 3, 2015 at 16:46
  • @vrklgn please add the plist name and path.
    – klanomath
    Commented Mar 3, 2015 at 17:14
  • @Asmus - Yeah but to access "Exclude Simple Hostnames" I'll have to do some black magic in the .plist file I'm afraid :/
    – vrklgn
    Commented Mar 3, 2015 at 19:40
  • @klanomath -/Library/Preferences/SystemConfiguration/preferences.plist
    – vrklgn
    Commented Mar 3, 2015 at 19:41

1 Answer 1

2

First of all, to get the UUIDs of your network sets, use PlistBuddy and perl:

 /usr/libexec/PlistBuddy -c "print :Sets" /Library/Preferences/SystemConfiguration/preferences.plist | perl -lne 'print $1 if /^    (\S*) =/'

this should return the IDs of the network sets. For each set you can then get the name with

/usr/libexec/PlistBuddy -c "print :Sets:698F419D-326E-45E3-8BE2-B0742334DD62:UserDefinedName" /Library/Preferences/SystemConfiguration/preferences.plist 

where, of course, you have to change the UUID accordingly. Now, you can print the ServiceOrder with:

/usr/libexec/PlistBuddy -c "print :Sets:698F419D-326E-45E3-8BE2-B0742334DD62:Network:Global:IPv4:ServiceOrder" /Library/Preferences/SystemConfiguration/preferences.plist

If you want to read the value for "ExcludeSimpleHostnames", you should be able to use

/usr/libexec/PlistBuddy -c "print :NetworkServices:69F7441B-BA1E-4DC3-B7DA-8D6302986F20:Proxies:ExcludeSimpleHostnames" /Library/Preferences/SystemConfiguration/preferences.plist 

while of course replacing this UUID with a valid one from the "ServiceOrder".

Update:

don't miss that you can set values with PlistBuddy, too:

/usr/libexec/PlistBuddy -c "Set :NetworkServices:$serviceid:Proxies:ExcludeSimpleHostnames 1" /Library/Preferences/SystemConfiguration/preferences.plist
1
  • Thank you @Asmus , I'll apply my final script as an answer above as well for people in the same situation to copy but this is the correct answer for the question posed :)
    – vrklgn
    Commented Mar 4, 2015 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .