Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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