mactypes で小一時間悩んだ

まずは曲を1曲、直接指定して登録してみようと思ってこんな感じにした。

>>> from appscript import *
>>> itunes = app("itunes")
>>> musicPath = "/Users/paraches/Documents/temp/mata.mp3"
>>> itunes.add(musicPath)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/appscript/reference.py", line 498, in __call__
appscript.reference.CommandError: Command failed:
		OSERROR: -35
		MESSAGE: Disk wasn't found.
		COMMAND: app(u'/Applications/iTunes.app').add('/Users/paraches/Documents/temp/mata.mp3')
>>> 

あれ? エラー?
「Disk wasn't found.」って、ボリュームが見つからないってことかな?
というわけで、/Volume から始まるパスに指定してからやってみたけど…

>>> musicPath = "/Volumes/other/Users/paraches/Documents/temp/mata.mp3"
>>> itunes.add(musicPath)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-universal/egg/appscript/reference.py", line 498, in __call__
appscript.reference.CommandError: Command failed:
		OSERROR: -35
		MESSAGE: Disk wasn't found.
		COMMAND: app(u'/Applications/iTunes.app').add('/Volumes/other/Users/paraches/Documents/temp/mata.mp3')
>>> 

相変わらずダメ…。


で、漸く調べてみようと言う気になってググってみたら…見つかったのが MacTypes さん。
知らなかった〜。
結局、こんな感じで曲データを iTunes のライブラリに加えることができた!

>>> musicPath = mactypes.Alias("/Volumes/other/Users/paraches/Documents/temp/mata.mp3")
>>> itunes.add(musicPath)
app(u'/Applications/iTunes.app').sources.ID(71).library_playlists.ID(203).file_tracks.ID(402)
>>> 

それにしても、こんなことで時間を食うとは思わなかった…