I have a folder of .mp3 files and want to be able to just play a random track.

I spent ages finding out how to make an AppleScript to count files in a folder, get a random number between 1 and the number of files. I was banging my head on how to then play that file. Then I discovered you can just ask for a random file in the folder. Then play it. Piece of cake! 🎶

-- 02 September 2023

-- Miraz Jordan, https://miraz.me

-- AppleScript picks a random .mp3 file from the Korolova folder

-- plays it with Quicktime Player

tell application "Finder"
	
	set random_file to some file of folder "Macintosh HD:Users:miraz:Korolova"
	
end tell

tell application "QuickTime Player"
	
	open random_file
	
	activate
	
	tell document 1
		
		play
		
	end tell
	
end tell