【问题标题】:Repeat function if variable is changed?如果变量改变,重复功能?
【发布时间】:2013-03-13 12:42:25
【问题描述】:

无法弄清楚这个循环 - 我希望仅在 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

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

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 发生变化,我需要重复整个函数

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

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

    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
    

    【讨论】:

    • 还是不行。我已经更新了我的代码,所以应用程序一直在运行,现在网站地址必须在专辑运行时更改if application "iTunes" is not running then return 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 set tempText to myText end if end tell tempText = myText open location "http://bandsite.com/shows/" & myText repeat while tempText = text of myText if tempText is not myText then open location "http://bandsite.com/show" & myText end if end repeat
    • 您是否尝试将我在答案中发布的脚本保存为保持打开状态的应用程序?
    • 是的 - 当我将它保存为保持打开的应用程序时,它根本不起作用。当我在苹果脚本编辑器中运行它时,它只返回专辑的日期(前 10 个整数),但不会打开网站。我需要它来打开一个网站,然后在专辑更改时更改网站地址
    • 我可以假设您在播放歌曲时打开了应用程序吗?如果没有,脚本会自动退出。
    • 你能详细说明“什么都没发生”吗?应用程序是否启动、退出、停留在 Dock 中?我是否也可以假设在您启动它并播放歌曲后,您将歌曲更改为另一张专辑中的歌曲?
    【解决方案2】:
    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
    

    试试这个

    希望这是你想要的...

    【讨论】:

    • 该语法根本不起作用,我尝试对其进行扩充,使其适合我需要它做的事情,但仍然没有运气[br]Set temptext = myText if temptext is not myText then 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 open location "http://bandsite.com/shows/" & myText repeat while temptext = text end repeat我收到一个语法错误,提示“A end of line 不能跟在这个标识符之后。”
    • 哦...对不起,我不知道这是什么语言..我认为这是一种伪语言..尝试遵循逻辑!如有不便,敬请原谅
    • 它的小程序。我想我真的很接近我只是无法弄清楚这个愚蠢的循环
    猜你喜欢
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2011-05-01
    • 2020-12-06
    相关资源
    最近更新 更多