How can I program my iPhone so it opens an app automatically when it connects to CarPlay or my car’s Bluetooth
You need to create a Personal Automation in the Shortcuts app.
When you initially create the automation, it will ask you for the condition that will cause it to launch.  There are several options like time of day, when you arrive or leave somewhere and even when something gets connected.  Select &quot;Bluetooth.&quot; (If your car supports CarPlay and you have it configured, you can select &quot;CarPlay&quot; instead)
Once you choose Bluetooth, you will how have the option to choose the specific device.  Select your car.
Then you can choose your action.  If you want to open a particular app, simply click on &quot;Add Action,&quot; select &quot;Scripting&quot; and then select &quot;Open App.&quot;  Tap on the &quot;Choose&quot; link to select your app.   When finished adding your action(s), tap next to see the summary.  Tap &quot;Done&quot; when finished.
When your iPhone connects to your car's Bluetooth, it will execute that action.  Keep in mind it can't differentiate when you disconnect and reconnect so if you happen to disconnect Bluetooth while driving and then reconnect it, it will launch the app again so you might want to add a simple confirmation dialog (yes/no) confirming you want to launch the app; this too can be done in &quot;Scripting.&quot;