Skip to content

Instantly share code, notes, and snippets.

@ybbond
Last active August 21, 2023 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ybbond/f09ad94de5376558cfe8276a2b460639 to your computer and use it in GitHub Desktop.
Save ybbond/f09ad94de5376558cfe8276a2b460639 to your computer and use it in GitHub Desktop.
This will trigger Safari.app mute or unmute without the need to "Allow JavaScript from Apple Events"
--------------------------------------------------------------------------------
# Auth: Yohanes Bandung Bondowoso
# dCre: 2021-07-11 20:52
# dMod: 2021-07-13 19:57
# Appl: System Events, Safari
# Task: Toggle Picture in Picture (PiP) on and off
# Libs: None
# Osax: None
# Aojc: None
# Tags: @Applescript, @Script, @System_Events, @Safari, @Mute
# Vers: 1.01
--------------------------------------------------------------------------------
try
tell application "System Events"
tell application "Safari"
set docItem to first item of documents
set tabName to name of docItem
end tell
tell application process "Safari"
tell window tabName
try
tell button 3 of group 4 of toolbar 1
perform action "AXShowMenu"
end tell
if exists (menu item "Mute This Tab" of menu 1 of group 4 of toolbar 1) then
click menu item "Mute This Tab" of menu 1 of group 4 of toolbar 1
else if exists (menu item "Unmute This Tab" of menu 1 of group 4 of toolbar 1) then
click menu item "Unmute This Tab" of menu 1 of group 4 of toolbar 1
end if
on error toolbarErrMsg
return "Error Level::Toggle Mute:" & space & toolbarErrMsg
end try
end tell
end tell
end tell
do shell script "killall System\\ Events"
on error errMsg
return "Error Level::Top:" & space & errMsg
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment