Add specific services to network location with terminal

automationNetworkterminal

I want to automate the creation of my network locations (say Home and Work) and was looking into networksetup -createlocation <location name> [populate]

Adding populate adds default services to the network location (USB LAN, Wi-Fi, Bluetooth PAN, Thunderbolt Bridge) and without leaves the location empty.

Is there a way to add specific services to a network location? networksetup -printcommands | grep -i location is not coming up with anything helpful.

Best Answer

networksetup uses a somehow hierarchical name system for the subcommands. location subcommands are used to manage locations itself only: you can either list, get (the current), create, delete or switch between locations.

Modifying the network services of a location is done in the networkservice "name space".

To manage the network services in one location you can either use "blacklisting" or a "whitelisting":

If you execute networksetup -createlocation <location name> with populate and remove unwanted network services it's blacklisting, without populate you have to add all required network services and it's rather whitelisting.

To remove a network service in case of blacklisting use:

... -removenetworkservice <networkservice>

To add a network service in case of whitelisting use:

...  -createnetworkservice <networkservice>