How to automatically connect Mac's Wi-Fi to iPhone's hotspot I am searching for a solution to automatically connect my MacBook Air to my iPhone hotspot. I don't like to connect manually every time. Is there any way to connect automatically.

Can I write a shell script file which will try to connect to my Hotspot so that I can add that task to system startup? Does that work? Is there any command to connect to a hotspot?
After connecting to the iPhone AP you should go in Network Preference and enable "Automatically join this network", as shown in the picture. You may also want to click "Advanced" and move the AP to change its priority (for example if you are at home you want the Mac to connect to your home's WiFi and not to the phone. So you should put the iPhone AP below the one at home - and/or work if any). 

I have enabled it myself, but for some reasons it didn't seem to stick. Right now, again in "Advanced", I have deleted the "RedPlanet" AP, applied the changes, connected my MBP to my iPhone again re-enabling the "Automatically Join" flag. 

That should be it, hopefully, unless being a connection from a mobile phone (thus with a data plan) macOS treats it differently (or if it is bugged. It worked randomly in the last couple of days that I enabled it)