Search code examples
macossafariapplescriptvideo-streamingvideo-player

Change video player position with AppleScript?


I have got a problem and I really don’t know how to solve it: I would like to change the player position of this / this video while it is opened in the background (so that another tab or application can be active at the same time). I can’t find anything helpful in the sourcecode and GUI scripting is not an option.

Thank you in advance!

EDIT: I came up with an idea: I changed the user agent to iOS 10 (iPhone) although I’m not sure if this makes the whole thing easier.


Solution

  • You can do this with AppleScript and JavaScript if the video player is using the HTML5 video tag. Like you said, changing your user agent to an iOS device increases your chances of being served this instead of a flash player.

    First, you need to search for the correct window by URL. Then, the script will run some Javascript in the window to update the time of the video. Change the properties to fit your usage. If the page has multiple video tags, you can change the [0] to which one by order on the DOM, or target by ID instead.

    property checkURL : "vimeo.com"
    property changeTime : 90
    try
        tell application "Safari"
            set theTab to first tab of window 1 whose URL contains checkURL
            do JavaScript "document.getElementsByTagName('video')[0].currentTime = " & changeTime in theTab
        end tell
    on error
        display dialog "That site is not loaded"
    end try