-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/22 21:30
# dMod: 2017/02/22 21:39
# Appl: Safari & System Events
# Task: Mute Sounds Playing in the Active Tab of Safari
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Mute, @Sounds, @Playing, @Active, @Tab, @Safari
-------------------------------------------------------------------------------------------
tell application "System Events"
tell application process "Safari"
tell (first window whose subrole is "AXStandardWindow")
tell toolbar 1
tell group 2
tell UI element 1
set muteButton to first button whose accessibility description contains "Mute"
tell muteButton
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
end tell
end tell
-------------------------------------------------------------------------------------------
I should have looked before writing it though – “Mute This Tab” & “Mute All Tabs” are available in Safari's Window menu and can be given keyboard shortcuts via the System Keyboard Prefs.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/22 21:30
# dMod: 2017/02/22 22:17
# Appl: Safari & System Events
# Task: Mute Sounds Playing in the Active Tab of Safari by activating “Mute” Menu Item.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Mute, @Sounds, @Playing, @Active, @Tab, @Safari
-------------------------------------------------------------------------------------------
tell application "System Events"
tell application process "Safari"
tell menu bar 1
tell menu bar item "Window"
tell menu 1
tell (first menu item whose name contains "Mute This Tab")
# tell (first menu item whose name contains "Mute All Tabs")
if its enabled is true then
perform action "AXPress"
else
beep -- error
end if
end tell
end tell
end tell
end tell
end tell
end tell
-------------------------------------------------------------------------------------------
This works fine with one odd caveat.
When using the “Mute All Tabs” option you cannot toggle it immediately – you have to wait about 2 seconds.
The “Must This Tab” option will toggle virtually instantly.