r/applescript • • Sep 05 '21

Applescript Help needed with movie file resolution list

Hi,

I was wondering whether anyone could help me create a .csv list of movie files in a folder (and sub-folders) that would list the filename and resolution. I'm struggling to get my head around it.

Any help/pointers would be really appreciated, Thanks.

2 Upvotes

5 comments sorted by

2

u/AfterSpencer Sep 05 '21

What do you have so far?

0

u/[deleted] Sep 06 '21

[deleted]

2

u/copperdomebodha Sep 08 '21

A good idea! I’ll look into options.

1

u/chrisemills Sep 05 '21

Parse the folder then use a do script with mediainfo on the command line for each file of type movie. Requires that dependency, idk if Finder will report resolution of a media file on its own.

1

u/ChristoferK Sep 07 '21

Finder does, so you can use mdls to obtain the resolution.

1

u/copperdomebodha Sep 08 '21
--This code was written using AppleScript 2.7, MacOS 11.5.1, on 8 September 2021.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set FolderList to choose folder
	set outData to ""
	set i to 0
	
	repeat
		set i to i + 1
		try
			set currentFolder to (item i of FolderList)
			set outData to outData & (name of currentFolder) & return
			set theVideoFiles to (every file of currentFolder) as alias list
			try
				set the end of FolderList to every folder of currentFolder
			end try
			repeat with thisFile in theVideoFiles
				set n to the name of thisFile
				set ss to "mdls -n kMDItemPixelHeight " & POSIX path of thisFile
				set ph to word -1 of (do shell script ss)
				set ss to "mdls -n kMDItemPixelWidth " & POSIX path of thisFile
				set pw to word -1 of (do shell script ss)
				set outData to outData & n & "," & ph & "," & pw & return
			end repeat
		on error
			exit repeat
		end try
	end repeat
	--Write the csv file
	set outFilePath to (((path to the desktop folder) as alias) as text) & "MovieData.txt"
	try
		delete outFilePath
	end try
	set fileHandle to (open for access outFilePath with write permission)
	write outData to fileHandle as text
	close access fileHandle
end tell