tell application "iTunes" if selection of front browser window is {} then display alert "歌詞ファイルをコピーする曲を選択して下さい。" buttons {"OK"} else set TID to AppleScript's text item delimiters -- text item delimiters を保存 set FI to fixed indexing -- fixed indexing を保存 set fixed indexing to true -- fixed indexing を true にセット set selectedTracks to selection -- 選択中のトラックを取得
try repeat with aTrack in selectedTracks tell aTrack set file_location to (the location of aTrack) -- 処置するトラックの場所を取得 set AppleScript's text item delimiters to ":" -- テキストを : で分割するように設定 set file_list to text items of (file_location as string) -- ファイルの完全パスをフォルダ名毎に分割 set (the item (the count of file_list) of file_list) to album & ".txt" -- ファイル名を「アルバム名.txt」に変更 set text_filename to file_list as string -- テキストファイルの完全パスを構築する set text_file to (open for access file text_filename) -- テキストファイルを開く set lyrics to read text_file -- 歌詞欄にテキストファイルを読み込む close access text_file -- テキストファイルを閉じる end tell end repeat end try set fixed indexing to FI -- fixed indexing を保存した値に戻す set AppleScript's text item delimiters to TID -- text item delimiters を保存した値に戻す display alert "作業を完了しました。" buttons {"OK"} end if end tell
set (the item (the count of file_list) of file_list) to album & ".jpg" -- ファイル名を「アルバム名.jpg」に変更 set art_filename to file_list as string -- 画像ファイルの完全パスを構築する set art_file to read (open for access file art_filename) as picture -- 画像ファイルを開く set data of artwork 1 to art_file -- アートワークに画像ファイルを読み込む close access art_file -- 画像ファイルを閉じる
>944 >『選択した曲と同一フォルダ内にある「.txt」の付いたファイルを歌詞へ登録』 tell application "iTunes" if selection is {} then error "えらんでください" set sndFileList to location of selection repeat with aFile in sndFileList tell application "Finder" set theFolder to folder of aFile set textFilePath to (files of theFolder where (its name ends with ".txt")) -- textFilePath に拡張子が".txt"のfileの参照のリストが入る。 -- ファイルがなかったとき{}。 -- 複数あったときの処理はどうする? set jpegFilePath to (files of theFolder where (its name ends with ".jpg")) -- jpegについても同様 end tell end repeat end tell
選択した曲と同一フォルダ内にある「album.txt」を歌詞へ登録』 tell application "iTunes" if selection of front browser window is {} then display alert "歌詞ファイルをコピーする曲を選択して下さい。" buttons {"OK"} else set TID to AppleScript's text item delimiters -- text item delimiters を保存 set FI to fixed indexing -- fixed indexing を保存 set fixed indexing to true -- fixed indexing を true にセット set selectedTracks to selection -- 選択中のトラックを取得 try repeat with aTrack in selectedTracks tell aTrack set file_location to (the location of aTrack) -- 処置するトラックの場所を取得 set AppleScript's text item delimiters to ":" -- テキストを : で分割するように設定 set file_list to text items of (file_location as string) -- ファイルの完全パスをフォルダ名毎に分割 set (the item (the count of file_list) of file_list) to "album.txt" -- ファイル名を album.txt に変更 set text_filename to file_list as string -- テキストファイルの完全パスを構築する set text_file to (open for access file text_filename) -- テキストファイルを開く set lyrics to read text_file -- 歌詞欄にテキストファイルを読み込む close access text_file -- テキストファイルを閉じる end tell end repeat end try set fixed indexing to FI -- fixed indexing を保存した値に戻す set AppleScript's text item delimiters to TID -- text item delimiters を保存した値に戻す display alert "作業を完了しました。" buttons {"OK"} end if end tell
上記スクリプトのどの部分を入れ替えると 『選択した曲と同一フォルダ内にある「.txt」の付いたファイルを歌詞へ登録』 になるのかな。。 tell application "iTunes" if selection is {} then error "えらんでください" set sndFileList to location of selection repeat with aFile in sndFileList tell application "Finder" set theFolder to folder of aFile set textFilePath to (files of theFolder where (its name ends with ".txt"))
読み込むファイル名を指定している箇所のキモだけ解説しますと set file_location to (the location of aTrack) ここで処置する曲(トラック)のファイルの場所のフルパスをfile_locationに入れて set AppleScript's text item delimiters to ":" set file_list to text items of (file_location as string) ここでfile_locationを":"で区切ってバラバラにしたものをfile_listに入れて set (the item (the count of file_list) of file_list) to album & ".txt" ここでfile_listの最後の項目を「その曲(トラック)のアルバム名.txt」に変更して set text_filename to file_list as string ここでバラバラにfile_listを":"で区切ったフルパスに戻してtext_filenameに入れてます。
先程OSX10.5+iTunes8環境で『テキストを歌詞に登録』を実行してみたところ テキストの冒頭がTo the...なのですが,登録された歌詞を見てみると oT とだけ登録されてました..冒頭の二文字だけでしかも逆になってる?? 10.5だとまた違うんでしょうね。
>>948さんの.txtを含む書類を認識させたスクリプトを何とか間に入れたいですがまだ成功せず。。 アートワークは何故登録されないんでしょうかね。 >>943のサイトを見ると set art_file to read (open for access file art_filename) as picture set data of artwork 1 to art_file なぜこれでペーストされないんでしょうね。。 プレビューで開いてアートワークにコピペでは貼り付けれるのに。。
>>956 いろんな箇所をいじってみたら set art_file to read (open for access file art_filename) as JPEG picture set data of front artwork to art_file でアートワークが登録されました! アドバイス有り難うございました。
皆様ご迷惑おかけしました。アートワークは諦めます。。 せめて登録するテキストを同一フォルダ内の「".txt"が含まれているもの」にする記述を教えていただけないでしょうか? set sndFileList to location of selection repeat with aFile in sndFileList tell application "Finder" set theFolder to folder of aFile set textFilePath to (files of theFolder where (its name ends with ".txt")) どうやってこれを入れたらいいやら。。
tell application "iTunes" if selection of front browser window is {} then display alert "歌詞ファイルをコピーする曲を選択して下さい。" buttons {"OK"} else set TID to AppleScript's text item delimiters -- text item delimiters を保存 set FI to fixed indexing -- fixed indexing を保存 set fixed indexing to true -- fixed indexing を true にセット set selectedTracks to selection -- 選択中のトラックを取得 try repeat with aTrack in selectedTracks tell aTrack set file_location to (the location of aTrack) -- 処置するトラックの場所を取得 set AppleScript's text item delimiters to ":" -- テキストを : で分割するように設定 set file_list to text items of (file_location as string) -- ファイルの完全パスをフォルダ名毎に分割 set (the item (the count of file_list) of file_list) to "album.txt" -- ファイル名を album.txt に変更 set text_filename to file_list as string -- テキストファイルの完全パスを構築する set text_file to (open for access file text_filename) -- テキストファイルを開く set lyrics to read text_file -- 歌詞欄にテキストファイルを読み込む close access text_file -- テキストファイルを閉じる end tell end repeat end try set fixed indexing to FI -- fixed indexing を保存した値に戻す set AppleScript's text item delimiters to TID -- text item delimiters を保存した値に戻す display alert "作業を完了しました。" buttons {"OK"} end if end tell
作成していただいた上記スクリプトに>>969さんらの tell application "Finder" set theFolder to folder of aFile set textFilePath to (files of theFolder where (its name ends with ".txt")) set text_file to textFilePath as alias をどこかの行と置換して set text_file to (open for access file text_filename) set lyrics to read text_file close access text_file ここ辺りに繋げるようにすればいいんですよね。。
難しいですね・・ tell application "iTunes" set sndFileList to location of selection repeat with aFile in sndFileList tell application "Finder" set theFolder to folder of aFile set textFilePath to (files of theFolder where (its name ends with ".txt")) set text_file to first item of textFilePath as alias end tell -----ここまででフォルダ内の.txtが指定されてますが・・ tell application "iTunes" set text_file to (open for access file text_file) -- テキストファイルを開く set lyrics to read text_file -- 歌詞欄にテキストファイルを読み込む close access text_file -- テキストファイルを閉じる end tell end repeat display alert "作業を完了しました。" buttons {"OK"} end tell
アートワークの登録は何とかreadしてset dataまで行ったんですが結果、登録できないです・・ close accessがあるとset fixed indexing to trueになり削除するとfalstになります。 readでJPEGが開き、やっと set data of artwork 1 of file track id 2166 of user playlist id 1580 of source id 39 to <data まで来たんですが登録されないんですよね。。
tell application "iTunes" set TID to AppleScript's text item delimiters -- text item delimiters を保存 set FI to fixed indexing -- fixed indexing を保存 set fixed indexing to true -- fixed indexing を true にセット set selectedTracks to selection -- 選択中のトラックを取得 try repeat with aTrack in selectedTracks tell aTrack set file_location to (the location of aTrack) -- 処置するトラックの場所を取得 set AppleScript's text item delimiters to ":" -- テキストを : で分割するように設定 set file_list to text items of (file_location as string) -- ファイルの完全パスをフォルダ名毎に分割 set (the item (the count of file_list) of file_list) to "album.jpg" -- ファイル名を album.jpg に変更 set art_filename to file_list as string -- 画像ファイルの完全パスを構築する set artworkData to read (open for access file art_filename) as JPEG picture -- 画像ファイルを開く set data of artwork 1 to artworkData -- アートワーク欄に画像ファイルを読み込む end tell end repeat end try set fixed indexing to FI -- fixed indexing を保存した値に戻す set AppleScript's text item delimiters to TID -- text item delimiters を保存した値に戻す end tell