m3u Script problem

Hi,

Im quite new to all this, but i’ve been working on a script that makes a m3u playlist from all the mp3 files within the active directory.

Although this script does what it is made fore the m3u files are not useable in quicktime. Probably i’m doing someting completely wrong, but i can’t find out what…

I would appreciate if you guys could have some suggestions.

Thx,

Bram



set theList to {}

tell application "Finder"
	set theLocation to (folder of the front window) as text
	set filelist to every file of the folder theLocation whose name ends with ".mp3"
	repeat with currentFile in filelist
		set currentFileName to (the name of currentFile)
		copy currentFileName to the end of theList
	end repeat
	
	set newFile to open for access file (theLocation & "00_playlist.m3u") with write permission
	set eof newFile to 0
	repeat with theItem in theList
		write theItem & return to newFile
	end repeat
	close access newFile
	
end tell


Hmm… strange:

I made this on an old iMac 2,1 Ghz G5 running osx 10.4.11 using applescript 1.10.7 (the mac on which i will use this script most of the time).

When i run the script on my intel macbook osx 10.5.7 running applescript 2.0.1 it works like a charm…

Anyone knows why this is and if there is a work-around this strange problem?

Hi,

Your script works. It writes all file names of the mp3 files in the front window into the text file

I have no idea about the m3u specification, but after reading the appropriate article on wikipedia it seams that the plain text file must contain much more than just the names of the files.

Well in fact it is just a plain text format. When i compare another m3u with mine. It looks exactly the same.

On Leopard it works great. Must be a bug in Tiger or quicktime i guess.

I tested your script successfully on a Tiger partition.
This is a faster version, it avoids the repeat loops


set {TID, text item delimiters} to {text item delimiters, return}
tell application "Finder"
	set theLocation to (target of front window) as text
	set theList to (name of every file of folder theLocation whose name ends with ".mp3") as text
end tell
set text item delimiters to TID

set newFile to open for access file (theLocation & "00_playlist.m3u") with write permission
set eof newFile to 0
write theList to newFile
close access newFile

Thx StefanK Now it works just fine on my iMac.

Can you briefly explain to my why one should use text item delimiters?

text item delimiters flattens the list of file names to CR separated paragraphs