Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mkozjak/d32ea2de1f99ca083fc536a97ff63e6c to your computer and use it in GitHub Desktop.
Save mkozjak/d32ea2de1f99ca083fc536a97ff63e6c to your computer and use it in GitHub Desktop.

Revisions

  1. mkozjak renamed this gist Aug 29, 2023. 1 changed file with 0 additions and 0 deletions.
  2. mkozjak revised this gist Aug 21, 2023. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions Toggle Safari Mute.applescript
    Original file line number Diff line number Diff line change
    @@ -37,11 +37,7 @@ on error pipErrMsg
    end tell

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

    -- click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1
    click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1 of window tabName
    end tell
    end tell

  3. mkozjak revised this gist Aug 21, 2023. 1 changed file with 45 additions and 32 deletions.
    77 changes: 45 additions & 32 deletions Toggle Safari Mute.applescript
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,55 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:52
    # dMod: 2021-07-13 19:57
    # Appl: System Events, Safari
    # Auth: Yohanes Bandung Bondowoso, Mario Kozjak
    # dCre: 2021-07-11 20:18
    # dMod: 2023-08-19 15:51
    # Appl: System Events, PIPAgent, 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
    # Aojc: True
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.05
    --------------------------------------------------------------------------------

    try
    tell application "System Events"
    tell application "Safari"
    set docItem to first item of documents
    set tabName to name of docItem
    if application "PIPAgent" is running then
    tell application "System Events"
    click button 3 of window "PIP" of application process "PIPAgent"
    end tell
    tell application process "Safari"
    tell window tabName

    try
    tell button 3 of group 4 of toolbar 1
    perform action "AXShowMenu"
    else
    error "Can’t get application process"
    end if
    on error pipErrMsg

    if pipErrMsg contains "Can’t get application process" or pipErrMsg contains "Can’t get window" then
    try
    tell application "Safari"
    set docItem to first item of documents
    set tabName to name of docItem
    end tell

    tell application "System Events"
    tell application process "Safari"
    set aWindow to window 1

    tell application "System Events"
    perform action "AXShowMenu" of button 2 of UI element tabName of UI element 1 of group 3 of toolbar 1 of aWindow
    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


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

    -- click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1
    end tell
    end tell
    end tell
    end tell
    do shell script "killall System\\ Events"
    on error errMsg
    return "Error Level::Top:" & space & errMsg
    end try

    do shell script "killall System\\ Events"
    on error safariErrMsg
    return "Error Level::Safari:" & space & safariErrMsg
    end try
    else
    return "Error Level::PIP Agent:" & space & pipErrMsg
    end if
    end try
  4. @ybbond ybbond revised this gist Jul 13, 2021. 1 changed file with 12 additions and 20 deletions.
    32 changes: 12 additions & 20 deletions Toggle Safari Mute.applescript
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:52
    # dMod: 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.00
    # Vers: 1.01
    --------------------------------------------------------------------------------

    try
    @@ -19,32 +19,24 @@ try
    end tell
    tell application process "Safari"
    tell window tabName

    try
    tell button 2 of radio button tabName of group "tab bar"
    tell button 3 of group 4 of toolbar 1
    perform action "AXShowMenu"
    end tell
    tell menu item 1 of menu 1 of button 2 of radio button tabName of group "tab bar"
    perform action "AXPress"
    end tell
    on error winErrMsg
    if winErrMsg contains "Can’t get group" then
    try
    tell button 3 of group 4 of toolbar 1
    perform action "AXShowMenu"
    end tell
    tell menu item 1 of menu 1 of group 4 of toolbar 1
    perform action "AXPress"
    end tell
    on error toolbarErrMsg
    return "Error Level::Toggle Mute from Tool Bar:" & space & toolbarErrMsg
    end try
    else
    return "Error Level::Toggle Mute from Tab Bar:" & space & winErrMsg
    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
  5. @ybbond ybbond revised this gist Jul 11, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Toggle Safari Mute.applescript
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:18
    # dMod: 2021-07-11 20:50
    # dCre: 2021-07-11 20:52
    # dMod: 2021-07-11 20:52
    # 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.02
    # Vers: 1.00
    --------------------------------------------------------------------------------

    try
  6. @ybbond ybbond created this gist Jul 11, 2021.
    50 changes: 50 additions & 0 deletions Toggle Safari Mute.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:18
    # dMod: 2021-07-11 20:50
    # 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.02
    --------------------------------------------------------------------------------

    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 2 of radio button tabName of group "tab bar"
    perform action "AXShowMenu"
    end tell
    tell menu item 1 of menu 1 of button 2 of radio button tabName of group "tab bar"
    perform action "AXPress"
    end tell
    on error winErrMsg
    if winErrMsg contains "Can’t get group" then
    try
    tell button 3 of group 4 of toolbar 1
    perform action "AXShowMenu"
    end tell
    tell menu item 1 of menu 1 of group 4 of toolbar 1
    perform action "AXPress"
    end tell
    on error toolbarErrMsg
    return "Error Level::Toggle Mute from Tool Bar:" & space & toolbarErrMsg
    end try
    else
    return "Error Level::Toggle Mute from Tab Bar:" & space & winErrMsg
    end if
    end try
    end tell
    end tell
    end tell
    on error errMsg
    return "Error Level::Top:" & space & errMsg
    end try