Automatically try to join hidden network if no preferred network available My work has a hidden SSID that I need to join every morning. Is there any way to make my Mac search for the hidden network if no preferred network is available?

Failing that, is there a command I can run from the terminal to connect to a specific SSID?

In my Network preferences, the hidden SSID is first on the list of preferred networks, but it still doesn't join when I'm in the office.

EDIT: It appears the answer below works if you've upgraded to Mojave. It did not work when I was on High Sierra.
I have a network with hidden SSID, which I configured using the "Join Other Network".

This was done years ago, and the network is joined when necessary.

You can see (and reorder) "remembered" networks in "Open Network Preferences" Advanced tab