Depending on the age of your WH-1000XM4 headphones, they do not ship with Bluetooth multi-point firmware and this needs to be updated using the Sony Headphones Connect Software for iOS. That also means that prior to that multi-point firmware update, you cannot concurrently pair your headphones to multiple devices, and you will need to unpair with the iPhone so that it is free to pair with your MacBook Air.
Once you have multi-point firmware support in the headphones, you still need that Sony Headphones Connect app to configure the multi-point connection and order to the iPhone and the MacBook Air. When done, and you power on the headphones, you will hear in succession: "Power on", the first Bluetooth connection, and then a third announcement about pairing to the secondary device.
I have the WH-1000XM4 and WF-1000XM4 devices and when I power on the WH device, it immediately connects to my M2 Mac mini Pro (Sonoma 14.1), and automatically becomes the sound output device when listening to a sound source. The WF-1000XM4 are dedicated to my iPhone 15 Pro Max (iOS 17.1) while out for long walks with my Music library.