将消息(iChat)状态设置为当前正在Radio中播放的歌曲

时间:2012-03-26 14:20:57

标签: applescript

我有以下脚本成功检索当前曲目并更新我的消息(iChat)状态,但为了使其自动工作,我想我需要在循环中运行它?建议吗?

tell application "Rdio"
    set theTrack to current track
    set theArtist to artist of theTrack
    set theName to name of theTrack
end tell

tell application "Messages"
    if status is available then
        set status message to ("♫ Playing in Rdio: " & (theArtist as string) & " - " & (theName as string))
    end if
end tell

1 个答案:

答案 0 :(得分:4)

除非Rdio能够在某些条件下触发脚本(你必须亲自检查,因为我自己不是一个Rdio用户 - 相当稀疏的Rdio AppleScript docs on site并没有表明任何相关内容),实现这一目标的最佳机会是将脚本存储为保持打开的AppleScript应用程序,并将脚本放在on idle处理程序中。 AppleScript Language Guide如果您想查找它,那么它就具有细节,但基本程序是:

  1. 将您的脚本包装在on idle处理程序中,即:

    on idle
        tell application "Rdio"
            set theTrack to current track
            set theArtist to artist of theTrack
            set theName to name of theTrack
        end tell
    
        tell application "Messages"
            if status is available then
                set status message to ("♫ Playing in Rdio: " & (theArtist as string) & " - " & (theName as string))
            end if
        end tell
    
        return 0 -- change this to stray from the default 30 sec. interval
    end idle
    
  2. 将脚本另存为 AppleScript应用程序,确保在保存表中检查保持打开

  3. 启动你新创建的AppleScript应用程序,你很高兴 - 它将继续运行,定期执行idle处理程序(默认情况下每30秒一次) - 你可以通过返回一个整数值来改变该值idle处理程序,将被评估为下次检查前的秒数。如果你想要花哨,并且Rdio AS接口支持它,你可以使用你歌曲的剩余播放时间,比如...)