Rampartisan
Rampartisan

Reputation: 427

Chrome,Youtube and AppleScript

I am trying to use applescript to set a youtube videos playpoint. For example when you press keys 0 - 9 on this video, the playpoint changes.

I have managed to tell chrome to keystroke 1 using this

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

Which returns a 1, but only is the address bar is highlighted. So my question is, how to I get focus onto the youtube video?

I'm definitely not a programmer, this is also my first time using apple script!

Upvotes: 1

Views: 929

Answers (2)

adayzdone
adayzdone

Reputation: 11238

A good excercise for you would be to validate the input. (Make sure the user text meets the required format before the dialog accepts the answer and moves on the next command).

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

Upvotes: 1

Obcure
Obcure

Reputation: 991

Maybe try and use keystroke tab to tab its way to the video instead of address bar Make sure you put this at the start after page load.

Upvotes: 0

Related Questions