如果变量变化,重复功能?

时间:2013-03-13 12:42:25

标签: applescript itunes

无法弄清楚这个循环 - 我希望下面的函数只在myText发生变化时重复(即个人正在收听的专辑发生变化) - 我已经能够循环播放一定次数或重复播放赛道改变了,但是我想让它在专辑发生变化时重复。

tell application "iTunes"
repeat if myText changes
if player state is playing then
    set albumName to (get album of current track)
    set myText to text 1 thru 10 of albumName
end if
end repeat
end tell

open location "http://bandsite.com/shows/" & myText

当代码在没有repeat命令的情况下工作时,它看起来像这样:

tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
set myText to text 1 thru 10 of albumName
end if
end tell

open location "http://bandsite.com/shows/" & myText 

我需要在myText更改的情况下重复整个函数

2 个答案:

答案 0 :(得分:0)

temptext = mytext
do
   if temptext != myText

      tell application "iTunes"
      if player state is playing then
      set albumName to (get album of current track)
      set myText to text 1 thru 10 of albumName
      end if
      end tell

     temptext = myText

   end if

while temptext==text

试试这个

希望这就是你想要的......

答案 1 :(得分:0)

将此保存为保持打开的应用程序:

property myList : {}

on run
    set albumA to my playCheck()
    if albumA ≠ false then
        set end of myList to albumA
    else
        quit -- Quit on the next idle.
        return 1 -- Please send the next idle as soon as possible.
    end if
end run

on idle
    set albumA to my playCheck()
    if albumA ≠ false then
        set end of myList to albumA
        if (item -1 of myList) ≠ (item -2 of myList) then
            open location "http://bandsite.com/shows/" & (text 1 thru 10 of albumA)
        end if
    end if
    return 3
end idle

on playCheck()
    tell application "iTunes"
        if player state is playing then return (get album of current track)
        return false
    end tell
end playCheck