【问题标题】:Applescript update iTunes stream title without obstructing rest of scriptApplescript 更新 iTunes 流标题而不妨碍脚本的其余部分
【发布时间】:2014-05-16 15:51:51
【问题描述】:

我正在使用下面的代码来获取当前的 iTunes 流标题。这很好用。就像我需要的那样,每次 iTunes 流标题更改时脚本都会更新,变量 Title 也会自行更新。

repeat
tell application "iTunes"
set Title to current stream title
end tell
delay 2
end repeat

但是,由于正在进行“重复”功能,脚本的其余部分将不会执行。您是否知道在 iTunes 更改其标题时仍然可以更新变量 Title 的任何方法,但不妨碍脚本的其余部分?好像它在后台运行?谢谢!

【问题讨论】:

    标签: applescript itunes repeat


    【解决方案1】:

    解决方案,使用处理程序(处理程序也称为函数、子例程或方法)。 将脚本的其余部分放在一个处理程序中,从循环中调用这个处理程序。

    像这样:

    set oldTitle to ""
    repeat
        set t to ""
        try
            tell application "iTunes" to set t to current stream title
        end try
        if t is not "" and t is not oldTitle then -- the title changed
            set oldTitle to t
            my doSomething(t) -- call the handler 
        end if
        delay 3
    end repeat
    
    on doSomething(Title)
        -- put the rest of the script here
    end doSomething
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多