[Pythonmac-SIG] Appscript, adding files to iTunes
Daniel Thorpe
danthorpe at zepler.net
Thu Apr 27 03:08:12 CEST 2006
Hi, I'm wondering if anyone can help me with an Appscript / iTunes
utility I'm trying to write. Does anyone know how I add m4a files to
my iTunes library using appscript?
So far, I have a list of filenames, which I want to add to my library
(which I've got a reference to). According to app('iTunes').add.help
() I have to pass the function a list of Alias(s). I think this means
Finder alias files, but I can't seem to be able to create them using
app('Finder').make().
This is my code so far....
import os,
from optparse import OptionParser
from appscript import *
def getListOfFinderItems(directory):
files = ["%s%s" % (directory, file,) for file in os.listdir(directory)]
# Need to make a list of 'alias files'
Finder = app('Finder')
# Finder.make.help()
# aliases = [None] * len(files)
# for i,file in enumerate(files):
# Finder.make(new=k.alias_file,at=aliases[i],to=file)
return aliases
def addToiTunes(directory):
audiofiles = getListOfFinderItems(directory)
iTunesApp = app('iTunes')
for src in iTunesApp.sources.get():
if src.kind.get() == k.library:
iTunesLib = src.playlists[1].get()
break
# iTunesApp.add.help()
iTunesLib.add.help()
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-f", "--folder", dest="folder", help="Select the
folder containing audio files.")
(options, args) = parser.parse_args()
addToiTunes(options.folder)
Cheers
Dan Thorpe
More information about the Pythonmac-SIG
mailing list