VLC.app: Play multiple movies on the pseudo VLC instances

Dumb, but really working solution to the problem with full user control over pseudo-instances. It takes about 1.5 minutes to wait until the new copy is verified by the system.


set movie1 to (choose file of type "public.movie")
set movie2 to (choose file of type "public.movie")

tell application "Finder"
	set VLC2 to duplicate (path to application "VLC")
	set VLC2name to name of VLC2
end tell

tell application VLC2name to open movie1
tell application "VLC" to open movie2

delay 60 -- to test only

tell application VLC2name to quit
tell application "System Events" to delete VLC2

Bash’s open command with the -n (new instance) option provides a straightforward way of opening multiple media files in separate VLC instances without having to make a copy of the application. I have been using the following AppleScript script for a couple of years. It screens all files currently selected in the Finder and opens any of them that are valid media files (i.e., that conform to the Uniform Type Identifier types public.movie or public.audio, or that the user has designated as media files in the specialMediaFileExtensions property based on their file extension):

use framework "Foundation"
use scripting additions
property || : current application

-- The user should place in the "specialMediaFileExtensions" list the file extensions of any valid (typically newly introduced) media file types whose Uniform Type Identifier (UTI) does not conform to the "public.movie" or "public.audio" UTI
-- As an example, "mkv", the file extension of Matroska videos, would have been placed in this list prior to it being assigned its current non-dynamic Uniform Type Identifier "io.mpv.mkv" that conforms to "public.movie"
property specialMediaFileExtensions : {}

-- Constant
set sharedWorkspaceObj to (||'s NSWorkspace)'s sharedWorkspace()
-- Get the HFS paths of all files currently selected in the Finder
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
try
	tell application "Finder" to set finderSelectionHFSPaths to (selection as text)'s paragraphs
end try
set AppleScript's text item delimiters to tid
-- Initialize the shell script that will open the media files
set shellScript to ""
-- Process the Finder selection files one at a time
repeat with currHFSPath in finderSelectionHFSPaths
	set isMediaFile to false
	-- Get the current file's UTI from its kMDItemContentType metadata property, and determine if the current file is a media file, i.e., whether its UTI conforms to the "public.movie" or "public.audio" UTI
	try
		set mdItem to (||'s NSMetadataItem's alloc()'s initWithURL:(currHFSPath as alias))
		set fileUTI to (mdItem's valueForAttribute:(||'s kMDItemContentType))
		tell sharedWorkspaceObj to set isMediaFile to (its |type|:fileUTI conformsToType:"public.movie") or (its |type|:fileUTI conformsToType:"public.audio")
	end try
	-- If the previous test does not indicate a media file, determine if the current file is a media file based on the user-determined "special media file extensions" test
	if not isMediaFile and (my specialMediaFileExtensions ≠ {}) then
		try
			set fileExtension to ((||'s NSString)'s stringWithString:(currHFSPath's POSIX path))'s pathExtension() as text
			set isMediaFile to {fileExtension} is in my specialMediaFileExtensions
		end try
	end if
	-- If the current file is a media file, add an "open -n" command for it in the shell script
	-- Note: The " || : " component will cause the "open" command to fail silently if an error occurs during its execution
	if isMediaFile then set shellScript to shellScript & "open -n -a VLC " & currHFSPath's POSIX path's quoted form & " || : ; "
end repeat
-- Execute the shell script to open the media files in separate instances of VLC
-- Note: The "export" command allows proper handling of any multibyte characters that may be present in the file name; the "&>/dev/null &" suffix causes the script to execute as a background osascript so that control may be returned to the user immediately after launching the script
if shellScript ≠ "" then do shell script ("export LANG='en_US.UTF-8' ; { " & shellScript & " } &>/dev/null & ")

Hi,

I wrote this article not just to launch these instances, but to fully control them in the future. For example, set the window bounds of each instance. Stop playback in the first instance window, decrease the sound level in the second instance window.

I know how to do it my way. How to do this with a do shell script “open -na” - is unknown to me.

For example, divide the computer display in half, then set the sound level in the 1st instance window to 0, and in the 2nd instance window to maximum. I would like a specific example with full control.

An example of controlling the sound volume using my method (I omit here creating/deleting the copy of VLC). So, create duplicate in the Finder manually, then run this:


set movie1 to (choose file of type "public.movie")
set movie2 to (choose file of type "public.movie")

-- tell application "Finder"
-- set VLC2 to duplicate (path to application "VLC")
-- set VLC2name to name of VLC2
-- end tell

set VLC2name to "VLC copy"

tell application "VLC"
	open movie1
	repeat until window 1 exists
		delay 0.02
	end repeat
	activate
	repeat 16 times
		volumeDown
	end repeat
end tell

using terms from application "VLC"
	tell application VLC2name
		open movie2
		repeat until window 1 exists
			delay 0.02
		end repeat
		activate
		repeat 16 times
			volumeUp
		end repeat
	end tell
end using terms from

delay 60 -- for testing visually

tell application VLC2name to quit
tell application "VLC" to quit

-- tell application "System Events" to delete VLC2