AppleScript to play 2 or more videos next to each other in-sync

hi all, I’m trying to achieve a side-by-side review of 2 or more videos using either VLC or QT.
The files can have random filename and are within the same folder as the script. For some reason I keep getting errors. Scripts I’ve tried are below…can anyone tell me what I’m doing wrong?

– Get the list of movie files in the same folder as the script
set scriptPath to path to me
set folderPath to (container of scriptPath) as text
set movieFiles to paragraphs of (do shell script "ls " & quoted form of POSIX path of folderPath & “/*.mp4”)

– Check if there are at least two movie files
if (count movieFiles) < 2 then
display dialog “There are not enough movie files in the folder.” buttons {“OK”} default button “OK”
return
end if

– Open QuickTime Player
tell application “QuickTime Player”
activate

-- Open the first movie file
set firstMovie to open item 1 of movieFiles

-- Open the second movie file
set secondMovie to open item 2 of movieFiles

-- Set the layout to side by side
set layout of document 1 to side by side
set layout of document 2 to side by side

-- Mute the sound for both movies
set volume of document 1 to 0
set volume of document 2 to 0

-- Start looping for both movies
set looping of document 1 to true
set looping of document 2 to true

end tell

– Get the list of movie files in the same folder as the script
set scriptPath to path to me
set folderPath to (container of scriptPath) as text
set movieFiles to paragraphs of (do shell script "ls " & quoted form of POSIX path of folderPath & “/*.mp4”)

– Check if there are at least two movie files
if (count movieFiles) < 2 then
display dialog “There are not enough movie files in the folder.” buttons {“OK”} default button “OK”
return
end if

– Open QuickTime Player
tell application “QuickTime Player”
activate

-- Open the first movie file
set firstMovie to open item 1 of movieFiles

-- Open the second movie file
set secondMovie to open item 2 of movieFiles

-- Set the layout to side by side
set layout of document 1 to side by side
set layout of document 2 to side by side

-- Mute the sound for both movies
set volume of document 1 to 0
set volume of document 2 to 0

-- Start looping for both movies
set looping of document 1 to true
set looping of document 2 to true

end tell

And the one I have for VLC

– Specify the folder path where your movies are located

set folderPath to POSIX path of “/Users/stepan.hluchan/Library/CloudStorage/OneDrive-Havas/Desktop/VLC_TEST”

– Get a list of video files in the folder

set videoFiles to paragraphs of (do shell script "ls " & quoted form of folderPath & “/*.mp4”)

– Open VLC player

tell application “VLC”

activate

– Loop through each video file and open in VLC

repeat with i from 1 to count videoFiles

set currentVideo to item i of videoFiles

open currentVideo

set currentMovie to item i of videoFiles

set current time of currentMovie to 0

set audio volume of currentMovie to 0

play currentMovie

– Calculate window position and size

set screenWidth to (item 3 of (get bounds of window 1))

set windowHeight to (item 4 of (get bounds of window 1))

set windowWidth to screenWidth / (count videoFiles)

– Set the position and size of the window

set bounds of window i to {((i - 1) * windowWidth), 0, (i * windowWidth), windowHeight}

end repeat

– Loop to keep the script running while movies are playing

repeat while (count of windows) > 0

delay 1

end repeat

– Stop and close the movies when done

stop

close every window

end tell

These scripts differ in how they position and size the QuickTime Player windows. I tested them on my Sonoma computer, and they worked as expected.

set movieFolder to (choose folder)

tell application "Finder" to set movieFiles to (every file in movieFolder whose name extension is "mp4") as alias list
if (count movieFiles) < 2 then display dialog "The selected folder contains one or no MP4 files" buttons {"OK"} cancel button 1 default button 1
set movieFiles to items 1 thru 2 of movieFiles

tell application "QuickTime Player"
	activate
	set movieOne to open item 1 of movieFiles
	set audio volume of movieOne to 0
	set looping of movieOne to true
	set bounds of window 1 to {10, 43, 955, 1000} -- set bounds as {x1, y1, x2, y2}
	set movieTwo to open item 2 of movieFiles
	set audio volume of movieTwo to 0
	set looping of movieTwo to true
	set bounds of window 1 to {965, 43, 1910, 1000} -- set bounds as {x1, y1, x2, y2}
	play movieOne
	play movieTwo
end tell
set movieFolder to (choose folder)

tell application "Finder" to set movieFiles to (every file in movieFolder whose name extension is "mp4") as alias list
if (count movieFiles) < 2 then display dialog "The selected folder contains one or no MP4 files" buttons {"OK"} cancel button 1 default button 1
set movieFiles to items 1 thru 2 of movieFiles

tell application "QuickTime Player"
	activate
	set movieOne to open item 1 of movieFiles
	set audio volume of movieOne to 0
	set looping of movieOne to true
	setPositionAndSize({10, 43, 945, 1000}) of me -- user set values as {x, y, w, h}
	set movieTwo to open item 2 of movieFiles
	set audio volume of movieTwo to 0
	set looping of movieTwo to true
	setPositionAndSize({965, 43, 945, 1000}) of me -- user set values as {x, y, w, h}
	play movieOne
	play movieTwo
end tell

on setPositionAndSize(positionAndSize)
	tell application "System Events" to tell process "QuickTime Player"
		set position of window 1 to {item 1 of positionAndSize, item 2 of positionAndSize}
		set size of window 1 to {item 3 of positionAndSize, item 4 of positionAndSize}
	end tell
end setPositionAndSize

It seems like it would be better to use visible screen frame, which would work with left- and right-aligned docks. For example:

-- revised 2023.01.06

use framework "AppKit"
use framework "Foundation"
use scripting additions

set {x1, y1, x2, y2} to getVisibleFrame() -- excludes menu bar and dock

set movieFolder to (choose folder)
tell application "Finder" to set movieFiles to (every file in movieFolder whose name extension is "mp4") as alias list
if (count movieFiles) < 2 then display dialog "The selected folder contains one or no MP4 files" buttons {"OK"} cancel button 1 default button 1
set movieFiles to items 1 thru 2 of movieFiles

tell application "QuickTime Player"
	activate
	set movieOne to open item 1 of movieFiles
	set audio volume of movieOne to 0
	set looping of movieOne to true
	set bounds of window 1 to {x1, y1, (((x2 - x1) div 2) + x1), y2} -- user modify as desired
	set movieTwo to open item 2 of movieFiles
	set audio volume of movieTwo to 0
	set looping of movieTwo to true
	set bounds of window 1 to {(((x2 - x1) div 2) + x1), y1, x2, y2} -- user modfy as desired
	play movieOne
	play movieTwo
end tell

on getVisibleFrame() -- bounds
	set theScreen to current application's NSScreen's mainScreen()
	set {{x1, y1}, {w1, h1}} to theScreen's frame()
	set {{x2, y2}, {w2, h2}} to theScreen's visibleFrame()
	return {x2 as integer, (h1 - h2 - y2) as integer, (x2 + w2) as integer, (h1 - y2) as integer}
end getVisibleFrame

Thanks a lot - those both work. I suppose there is no way though sync the both movies… so say if I press pause on movie 1 - movie 2 pauses too…or if I move in position on movie 1 to some point, it does the same with movie 2? I guess that would go beyond the automation possibilities of AppleScript - since the script would have to be ‘listening’ right?

That’s correct.

Just as a point of information, QuickTime Player does have a pause command and current time property. So, you could pause both movies with a script. And, you could prompt for a specific time for both movies or set the current time of one movie to that of the other. For example:

tell application "QuickTime Player"
	set theTime to current time of document 1
	set current time of document 2 to theTime
end tell

On my Sonoma computer, the result is a real not an integer value.