【发布时间】:2021-03-18 03:50:25
【问题描述】:
to clickClassName(theClassName, elementnum)
tell application "Google Chrome"
set youtubeTab to (the first tab of window 2 whose URL contains "youtube")
end tell
tell application "Google Chrome"
execute youtubeTab javascript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();"
end tell
end clickClassName
clickClassName("ytp-play-button ytp-button", 0)
我的 MacBook 上打开了两个窗口。一个在 MacBook 上,另一个在外接显示器上。我想在我的 MacBook 上做笔记时播放/暂停在外部显示器上播放的 YouTube 视频。上述脚本仅在 MacBook 上的窗口被激活时才有效,因为它通过window 2 专门指向另一个窗口。
我想我需要找到所有窗口并以某种方式使用repeat 运算符,以便无论激活哪个窗口,我都可以播放/暂停视频。但我不知道如何接近。
感谢任何帮助!
PS。我已将此脚本添加为服务并分配了特定的组合键。因此,当我在 MacBook 上做笔记时,我可以快速播放/暂停视频。
【问题讨论】:
-
我正在观看大量的讲座并且有完全相同的问题。你能利用下面的脚本吗?你有没有想过如何倒带视频?
标签: windows macos youtube tabs applescript