• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Toggle – Mute Sound Playing in Active Safari Tab
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Toggle – Mute Sound Playing in Active Safari Tab


  • Subject: Toggle – Mute Sound Playing in Active Safari Tab
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 22 Feb 2017 22:22:07 -0600

Hey Folks,

Just posted this to MacScripter.net.

-------------------------------------------------------------------------------------------
# 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.

Curiously the “Mute All Tabs” button is NOT available to ui-scripting.

So, let's try scripting the menu items:

-------------------------------------------------------------------------------------------
# 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.

--
Best Regards,
Chris


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: tools !!!!
  • Next by Date: Scripting Better Applescript support requests !
  • Previous by thread: Re: tools !!!!
  • Next by thread: Scripting Better Applescript support requests !
  • Index(es):
    • Date
    • Thread