Headphone jack broke and got stuck in headphone socket MacBook Pro The tip of the headphone jack got stuck in the headphone socket of my MacBook Pro and I have the following question:

The "Sound" option in the System Preferences displays sound output through the "Headphones"

However as the headphone's jack is broken, the headphone doesn't work.

If I pull the headphone out, the "Speaker" icon in the menu bar greys out and sound seems disabled.

If I plug in the headphone in, the "Speaker" icon in the menu bar appears as working however as the headphone itself is broken, there is no sound.

Where I live, it is not possible to buy a micro screwdriver to open the MacBook Pro and push away the headphone jack from the headphone plug.

As a temporary solution I would like to use some AppleScript or other program code to force sound output through the MacBook Pro's speakers instead of the headphones, while the headphones are plugged in.
Depending on the breakage, you may not be able to control the software if the "jack detection" sensor is intermittent. It will over rule whatever software setting you have made and send output to the headphone jack each time it senses an insertion.

Often taking this to Apple at a genius bar is no cost if they can dislodge the broken piece with experience (and same for reputable repair shops). Also, you might only pay labor if the jack isn't broken. Usually there is more damage since why would a protected piece break off inside a perfectly functioning receptacle, but it's possible you broke the jack mostly or entirely before inserting it.

Give a shot at setting the sound in the System Preferences, but most of the times this happens, you'll need to get a repair if you can't use software to switch the output once and have it stick.