I recently came across a Raycast extension that allows you to play/pause music from YouTube music while it’s running in your browser. After exploring how it worked internally given I was a bit astonished it is even possible, I found that it’s all just using AppleScript.
So, a bit of bash code later and I had a working implementation of a new
windows with a given URL.
Here’s the command that will play music from YouTube music like what the Raycast extension was doing. But this now can be a terminal command!
js --url music.youtube.com "document.querySelector('#play-pause-button[aria-label=Play]').click()"
In Chromium based browsers (e.g. Chrome, Arc), you need to enable a developer flag in order for this to work properly. You can find it in the menu: