Mac の Skype に iTunes で再生してる曲を表示

December 17th, 2006

Fuck食場 のがかっこいいのでまねしてみた。

on idle
    updateSkype()
    return 30
end idle

on updateSkype()
    set str to "(Not playing now...)"

    tell application "iTunes"
        if (player state) is playing then
            set str to (name of current track) & " / " & (artist of current track)
        end if
    end tell

    tell application "Skype"
        send command "SET PROFILE MOOD_TEXT " & str script name "NowPlayingOnSkype"
    end tell
end updateSkype

スクリプトエディタで、フォーマットを「アプリケーション」にして「実行後、自動で終了しない」にチェックをいれて保存。できたファイルをダブルクリックすれば起動する。スクリプトの再編集はメニューバーの Edit から。

Mac から使える Skype API は、ミニ言語を文字列でわたさなきゃいけないのが微妙だと思う。これは AppleScript だけじゃなくて Cocoa, Carbon でもおなじ。あと SET AVATAR が実装されていないので、画像は変更できない。

on idle で30秒ごとにポーリングしているところも、iTunes から NSDistributedNotificationCenter 経由で com.apple.iTunes.playerInfo をうけとるようにしたいんだけど、AppleScript から notification まわりはさわれないようだ。