2013-03-06 98 views
1

我想使用的AppleScript设置YouTube视频的播放点。例如,当您按此视频上的键0 - 9时,播放点会更改。Chrome和YouTube和AppleScript

我设法让Chrome使用此

tell application "Google Chrome" 
    activate 
tell application "System Events" to tell process "Google Chrome" to key code 83 
end tell 

返回一个1到击键1,但仅是地址栏高亮显示。所以我的问题是,如何将焦点放在YouTube视频上?

我绝对不是一个程序员,这也是苹果使用脚本我第一次!

回答

1

一个很好的锻炼; Tibial你将是验证输入。 (确保用户文本在对话接受答案并在下一个命令上移动之前满足所需的格式)。

set videoUrl to "https://www.youtube.com/watch?v=o6xchtAsq4U" 
set AppleScript's text item delimiters to ":" 
set {min, sec} to text items of (text returned of (display dialog "Enter start time… minutes:seconds" default answer "1:15")) 
set AppleScript's text item delimiters to {""} 

tell application "Google Chrome" 
    if not (exists window 1) then reopen 
    set URL of active tab of window 1 to videoUrl & "&t=" & min & "m" & sec & "s" 
end tell 
+0

我找到了我的答案,我错了键码,它是18不是83. 感觉愚蠢 感谢您的帮助! – Rampartisan 2013-03-07 02:49:48

+0

@ user2142136和adayzdone什么是关键代码? – Unheilig 2015-01-02 20:55:12

0

也许尝试使用按键选项卡标签的方式向视频,而不是地址栏确保您的页面加载后,把这个在开始。

+0

我发现我的回答,我有错键码,它是18不是83 愚蠢 感谢您的帮助反正感觉! – Rampartisan 2013-03-07 02:49:07