script for youtube video on anybrowser

hi, i have 2 screens and often watching tutorial on youtube with the second screen,
the good thing with the key f8 i can pause/play the video that run even when im on xcode for example
unfortunately i was hopping that f7 and f9 can bring me the back forward 5sec or move forward 5sec functionality of yt, but nothing.
is it possible to create a script to do that ?
this can save a lot of time avoiding going back to the browser each time i want to move backward in the video

hi @Andreas_Hegenberg do you think you can help me with that ?

im trying to learn apple script since yesterday, but im block, i tried this for chrome or brave to fastforward 10sec but its not working .

Blockquote

tell application "Google Chrome"
    repeat with t in tabs of windows
        tell t
            if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
                execute javascript "
            var player = document.querySelector('video');
            player.seekTo(player.getCurrentPosition() + 10000);
            "
                exit repeat
            end if
        end tell
    end repeat
end tell

Your problem is not AppleScript, but JavaScript. The (YouTube-) player has no function "seekTo" and "getCurrentPosition".

Try this to fast forward by 10 seconds:

tell application "Google Chrome"
    repeat with t in tabs of windows
        tell t
            if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
                execute javascript "
            var player = document.querySelector('video');
            player.currentTime = player.currentTime + 10;
            "
                exit repeat
            end if
        end tell
    end repeat
end tell

ohh god , its working, thanks you very much you are the best

if i want to run this code on different app. do you know if it possible with apple script to do a tell application on multiple app like for example :
tell application "Google Chrome", "brave", "safari" ?

No. You have to write a statement for each app. The JavaScript Code (e.g. the player object) may be also different.

ok thanks Dirk :relaxed:

What you can do is to use a loop:

set appList to {"Google Chrome", "Safari", "Brave"}
repeat with theApp in appList
	tell application theApp
		-- your code
	end tell
end repeat

But that doesn't make sense from my point of view, because the tab handling in the browsers is too different. But you can try.

no its not working :smiling_face_with_tear:,and previously i wrote a statement for each browser, but only chrome is working, i guess its because of what you said "the tab handling". and i dont know how to make the change...

Here is the script for Safari:

Note: "You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use 'do JavaScript'."

tell application "Safari"
    repeat with t in tabs of windows
        tell t
            if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
                do JavaScript "
            var player = document.querySelector('video');
            player.currentTime = player.currentTime + 10;
            "
                exit repeat
            end if
        end tell
    end repeat
end tell

I can't help you with the Brave browser as I don't have it installed, but you can try to add it to the Script Editors Dictionary (under windows) to see if it is scriptable and if so, what the commands are. See: change browser in script to work with brave browser instead of safari - #2 by Caliguvara

thanks very much Dirk ill try today :relaxed: