Enter Picture in Picture menu item on Safari using AppleScript

Hi, guys,

I came across this great AppleScript on GitHub that is supposed to toggle Picture-in-Picture feature on Safari, but, unfortunately, it’s a bit outdated and does not work with macOS Ventura. Seems like the perform action "AXShowMenu" cannot be accomplished because the hierarchy (of the window(s)) changed.

Are there any guys that are experts in accessibility that can suggest a possible patch? I’m trying to trigger the stock Safari Enable Picture-in-Picture context menu item that is situated on the Mute All Tabs button on a tab that has active (YouTube) media playing.

Thanks, all!

1 Like

Edit: Done! Here it is! It’s not perfect, but for now it works good enough.

2 Likes

If there’s anyone who can make this work without my manual click-click hackery, that’d be amazing! Patches welcome.

delay 0.2
keystroke "Down"
keystroke "Down"
keystroke return

Should be substituted with something along these lines:

click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1
1 Like

Fixed. Should’ve been click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1 of window tabName.

2 Likes