Skip to content

Instantly share code, notes, and snippets.

@ybbond
Last active March 5, 2025 14:36
Show Gist options
  • Select an option

  • Save ybbond/47d6fce6ce500748a0cfb7841cd0c64b to your computer and use it in GitHub Desktop.

Select an option

Save ybbond/47d6fce6ce500748a0cfb7841cd0c64b to your computer and use it in GitHub Desktop.

Revisions

  1. ybbond revised this gist Jul 13, 2021. 1 changed file with 8 additions and 17 deletions.
    25 changes: 8 additions & 17 deletions Trigger Safari PiP.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 21:07
    # dMod: 2021-07-13 20:01
    # Appl: System Events, PIPAgent, Safari
    # Task: Toggle Picture in Picture (PiP) on and off
    # Libs: None
    # Osax: None
    # Aojc: True
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.03
    # Vers: 1.04
    --------------------------------------------------------------------------------

    try
    @@ -28,25 +28,16 @@ on error pipErrMsg
    end tell
    tell application "System Events" to 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
    click menu item "Enter Picture in Picture" of menu 1 of button 2 of radio button tabName of group "tab bar"
    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
    click menu item "Enter Picture in Picture" of menu 1 of group 4 of toolbar 1
    on error toolbarErrMsg
    return "Error Level::Toggle Mute from Tool Bar:" & space & toolbarErrMsg
    end try
    else
    return "Error Level::Toggle PiP from Tab Bar:" & space & winErrMsg
    end if
    click menu item "Enter Picture in Picture" of menu 1 of group 4 of toolbar 1
    on error toolbarErrMsg
    return "Error Level::Toggle PiP:" & space & toolbarErrMsg
    end try

    end tell
    end tell
    do shell script "killall System\\ Events"
  2. ybbond revised this gist Jul 11, 2021. 1 changed file with 11 additions and 12 deletions.
    23 changes: 11 additions & 12 deletions Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,24 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:18
    # dMod: 2021-07-11 20:50
    # dMod: 2021-07-11 21:07
    # Appl: System Events, PIPAgent, Safari
    # Task: Toggle Picture in Picture (PiP) on and off
    # Libs: None
    # Osax: None
    # Aojc: None
    # Aojc: True
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.02
    # Vers: 1.03
    --------------------------------------------------------------------------------

    try
    tell application "System Events"
    if exists (window "PIP" of application process "PIPAgent") then
    tell application process "PIPAgent" to tell window "PIP"
    click button 3
    end tell
    else
    error "Can’t get application process PIPAgent"
    end if
    end tell
    if application "PIPAgent" is running then
    tell application "System Events"
    click button 3 of window "PIP" of application process "PIPAgent"
    end tell
    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
    @@ -51,6 +49,7 @@ on error pipErrMsg
    end try
    end tell
    end tell
    do shell script "killall System\\ Events"
    on error safariErrMsg
    return "Error Level::Safari:" & space & safariErrMsg
    end try
  3. ybbond revised this gist Jul 11, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # Task: Toggle Picture in Picture (PiP) on and off
    # Libs: None
    # Osax: None
    # Aojc: True
    # Aojc: None
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.02
    --------------------------------------------------------------------------------
  4. ybbond revised this gist Jul 11, 2021. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,25 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:18
    # dMod: 2021-07-11 20:24
    # dMod: 2021-07-11 20:50
    # Appl: System Events, PIPAgent, Safari
    # Task: Toggle Picture in Picture (PiP) on and off
    # Libs: None
    # Osax: None
    # Aojc: True
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.01
    # Vers: 1.02
    --------------------------------------------------------------------------------

    try
    tell application "System Events" to tell application process "PIPAgent" to tell window "PIP"
    click button 3
    tell application "System Events"
    if exists (window "PIP" of application process "PIPAgent") then
    tell application process "PIPAgent" to tell window "PIP"
    click button 3
    end tell
    else
    error "Can’t get application process PIPAgent"
    end if
    end tell
    on error pipErrMsg
    if pipErrMsg contains "Can’t get application process" or pipErrMsg contains "Can’t get window" then
  5. ybbond revised this gist Jul 11, 2021. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,16 @@
    --------------------------------------------------------------------------------
    # Auth: Yohanes Bandung Bondowoso
    # dCre: 2021-07-11 20:18
    # dMod: 2021-07-11 20:24
    # Appl: System Events, PIPAgent, Safari
    # Task: Toggle Picture in Picture (PiP) on and off
    # Libs: None
    # Osax: None
    # Aojc: True
    # Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
    # Vers: 1.01
    --------------------------------------------------------------------------------

    try
    tell application "System Events" to tell application process "PIPAgent" to tell window "PIP"
    click button 3
  6. ybbond revised this gist Jul 11, 2021. 1 changed file with 32 additions and 44 deletions.
    76 changes: 32 additions & 44 deletions Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -1,53 +1,41 @@
    try
    tell application "System Events"
    tell application "System Events" to tell application process "PIPAgent" to tell window "PIP"
    click button 3
    end tell
    on error pipErrMsg
    if pipErrMsg contains "Can’t get application process" or pipErrMsg contains "Can’t get window" then
    try
    tell application process "PIPAgent" to tell window "PIP"
    tell button 3
    perform action "AXPress"
    end tell
    tell application "Safari"
    set docItem to first item of documents
    set tabName to name of docItem
    end tell
    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 process "Safari"
    tell window tabName
    tell application "System Events" to tell application process "Safari"
    tell window tabName
    try
    tell button 2 of radio button tabName of group "tab bar"
    perform action "AXShowMenu"
    end tell
    click menu item "Enter Picture in Picture" of menu 1 of button 2 of radio button tabName of group "tab bar"
    on error winErrMsg
    if winErrMsg contains "Can’t get group" then
    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 "Enter Picture in Picture" 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 "Enter Picture in Picture" 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 PiP from Tab Bar:" & space & winErrMsg
    end if
    click menu item "Enter Picture in Picture" of menu 1 of group 4 of toolbar 1
    on error toolbarErrMsg
    return "Error Level::Toggle Mute from Tool Bar:" & space & toolbarErrMsg
    end try
    end tell
    end tell
    on error safariErrMsg
    return "Error Level::Safari:" & space & safariErrMsg
    end try
    else
    return "Error Level::PIP Agent:" & space & pipErrMsg
    end if
    else
    return "Error Level::Toggle PiP from Tab Bar:" & space & winErrMsg
    end if
    end try
    end tell
    end tell
    on error safariErrMsg
    return "Error Level::Safari:" & space & safariErrMsg
    end try
    end tell
    on error errMsg
    return "Error Level::Top:" & space & errMsg
    else
    return "Error Level::PIP Agent:" & space & pipErrMsg
    end if
    end try
  7. ybbond created this gist Jul 11, 2021.
    53 changes: 53 additions & 0 deletions Trigger Safari PiP.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    try
    tell application "System Events"
    try
    tell application process "PIPAgent" to tell window "PIP"
    tell button 3
    perform action "AXPress"
    end tell
    end tell
    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 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 "Enter Picture in Picture" 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 "Enter Picture in Picture" 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 PiP from Tab Bar:" & space & winErrMsg
    end if
    end try
    end tell
    end tell
    on error safariErrMsg
    return "Error Level::Safari:" & space & safariErrMsg
    end try
    else
    return "Error Level::PIP Agent:" & space & pipErrMsg
    end if
    end try
    end tell
    on error errMsg
    return "Error Level::Top:" & space & errMsg
    end try