/
togglepip.scpt
69 lines (62 loc) · 2.12 KB
/
togglepip.scpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--------------------------------------------------------------------------------
# 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: True
# Tags: @Applescript, @Script, @System_Events, @PictureInPicture, @PiP, @Safari
# Vers: 1.05
--------------------------------------------------------------------------------
try
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
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if frontApp = "Safari" 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
delay 0.1
click menu item "Enter Picture in Picture" of menu 1 of group 3 of toolbar 1 of window tabName
end tell
end tell
do shell script "killall System\\ Events"
on error safariErrMsg
return "Error Level::Safari:" & space & safariErrMsg
end try
else if frontApp = "IINA" then
try
tell application "System Events"
tell application process "IINA"
try
click menu item "Enter Picture-in-Picture" of menu "Video" of menu bar 1
on error
click menu item "Exit Picture-in-Picture" of menu "Video" of menu bar 1
end try
end tell
end tell
on error iinaErrMsg
return "Error Level::IINA:" & space & iinaErrMsg
end try
end if
else
return "Error Level::PIP Agent:" & space & pipErrMsg
end if
end try