Send keystroke to Chrome, to specific tab

I have this web player for music ibroadcast.com

I like having a key to play/stop the music (F12) when I'm listening on Spotify's app, for example, but that's an app, not a tab on a browser.

Can I have a macro that runs in the background without opening Chrome, that scans all windows and all tabs on each window and when it finds the one with ibroadcast.com sends the SPACE keystroke to that tab only? All in the background.

Is it important to you that the tab for ibroadcast be amongst all the other tabs? Unless it is, I would suggest that you base your macro on either of the following starting points.

The only Chromium browser that I currently use is Brave, and it uses different terminology than Chrome does, so I’ll trust some linked online sources to explain the details.

  1. Use Chrome to create a desktop app for the site. Then you should be able to directly call up that application from your macro.

  2. Add a new profile (“person”) in Chrome just for use with ibroadcast. (In Brave, profiles appear in a menu in the menu bar, so they are easy to access from a macro; I seem to recall that it may be trickier in Chrome, but there will be a way).

The above techniques are also available in a number of non-Chromium browsers.

No. It will be sometimes, and sometimes it won't.

I will have to check option one then. That sounds like a good option. Thanks!

ibroadcast.com demands an account, so I haven't been gone and looked, but maybe you can start/stop play with JavaScript like you can on YouTube.

If so you could use a KM AppleScript action and target the correct tab of the appropriate window with the execute javascript command (tested with Chrome and YouTube in a background tab in a background window, so the theory works...).

1 Like

I used a few variations of the AppleScript below for other websites, but it can likely be adapted for iBroadcast.com. You’ll probably need to update the selector from 'audio' to something more specific to iBroadcast’s player (I don’t have an account, so I can't confirm the exact structure).

I also use other methods that rely on the "Now Playing" in the menu bar, though these require installing some CLI tools. They might be unnecessary for your use case, but can be useful if you have multiple tabs open on the same domain.

tell application "Google Chrome"
	set windowList to every window
	repeat with aWindow in windowList
		set tabList to every tab of aWindow
		repeat with aTab in tabList

			if URL of aTab contains "ibroadcast.com" then

				execute aTab javascript "

				document.querySelector('audio').paused 
				? document.querySelector('audio').play() 
				: document.querySelector('audio').pause();

				"
				return
			end if
		end repeat
	end repeat
end tell
3 Likes

Thank you so much!

After a few changes with the help of ChatGPT I was able to make it work using:

tell application "Google Chrome"
	set windowList to every window
	repeat with aWindow in windowList
		set tabList to tabs of aWindow
		repeat with aTab in tabList
			if URL of aTab contains "ibroadcast.com" then
				execute aTab javascript "
					document.querySelector('.mgr-player-play')?.click();
				"
				return
			end if
		end repeat
	end repeat
end tell

I will mark this (my) reply as the Solution in case someone else wants to do the same with iBroadcast, but the credit goes all to you :wink:

2 Likes