(* Radio の情報をリストファイルに書き出す iTunes用 AppleScript
*
* 動作要件
* ・Mac OS X 10.5 以上 (Mac OS X 10.5.8 で動作確認済み)
* ・iTunes 9 以上 (iTunes 9.1 で動作確認済み)
* ※iTunes 7 では動かないので注意!
*
* 保存
* ・AppleScript の場合: スクリプトバンドル形式か、スクリプト形式で保存
* ・Automator の場合: ワークフロー
*
* 使い方
* 1. スクリプトを起動し、ダイアログに従う
*
* 書き出しについて
* ・トラック名(プレイリスト): トラック名(ストリーム)
* ・~/Music/radio_list.txt
*
* その他
* ・Automator の AppleScript でも動くようにしたので、ダイアログ周りがちょっと複雑。
* using terms from application "Finder" を使用した。
* Automator を考えなければ、tell me activate... とするのが良いだろう。
*
*)
on run
-- property
set dname to (path to music folder) as text -- $HOME/Music
set fname to "radio_list.txt"
set full_path to dname & fname -- $HOME/Music/fname
-- dialog text
set ttl1 to "Radio Info List Maker"
set msg1 to "リストファイルに追加しますか?"
set msg2 to "リストファイルを開きますか?"
try
-- iTunes
tell application "iTunes"
set track_name to name of current track
set stream_title to current stream title
if stream_title is missing value then return
end tell
-- me
tell me
using terms from application "Finder"
display dialog msg1 default answer stream_title with title ttl1
set res to text returned of result
end using terms from
-- go!
set sh1 to "trc=" & quoted form of track_name & ";"
set sh2 to "res=" & quoted form of res & ";"
set sh3 to "lst=" & quoted form of fname & ";"
set sh4 to "tmp='radio_temp.list';"
set sh5 to "cd " & quoted form of (POSIX path of dname) & " && "
set sh6 to "echo \"${trc}: ${res}\" >>\"${lst}\";"
set sh7 to "sort -f \"${lst}\" | uniq >\"${tmp}\";"
set sh8 to "rm \"${lst}\" && mv \"${tmp}\" \"${lst}\";"
--
do shell script (sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8)
(* CotEditor で開く
set my_app to "CotEditor"
-- open file?
using terms from application "Finder"
display dialog msg2 with title ttl1
end using terms from
-- open file
tell application my_app
activate
open full_path
end tell
*)
end tell
on error err_msg
return err_msg
end try
end run