Mac でも iTunes で今聞いている曲を Blog エントリに掲載
Hacking the Hack #92: iTunes COM API で今聞いている曲を Blog エントリに掲載 を見て、Mac でもやってみました。もちろん AppleScript で。
property mtUrl : "https://app.cocolog-nifty.com/t/app/weblog/post"
property blogID : 21024
tell application "iTunes"
set theTrack to current track
set strNowPlaying to "Now Playing: " & artist of theTrack & " - " & name of theTrack & " (" & album of theTrack & ")"
end tell
set urlNewEntry to mtUrl & "?blog_id=" & blogID
tell application "Safari"
activate
make new document
set URL of document 1 to urlNewEntry
-- call the sub-routine and pass the maximum number of seconds to wait for the page to be loaded:
if page_loaded(20) of me is false then error numner - 128
do JavaScript "document.forms['entry_form'].text_more.value = ¥"" & strNowPlaying & "¥"" in document 1
end tell
(*
from http://www.apple.com/applescript/safari/jscript.01.html
*)
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
結果はこんな感じ↓
Now Playing: Björk - Pleasure Is All Mine (Medúlla)
Safari の場合、AppleScript で DOM を直接叩けるわけではないので、JavaScript を組み立てる必要があります。ほんとは曲名とかにダブルクオートが入ってるときの処理とか必要な気がしますが、めんどいのでさっくり省略...


Comments
なんかよくわからんがすてきだな
ビョーク大好き
おっ
Posted by: じゃいこ | 2005.01.26 at 07:47 PM