Applescript在不妨碍脚本其余部分的情况下更新iTunes流标题
我正在使用下面的代码获取当前的iTunes流标题。这很有效。就像我需要的那样,每次iTunes流标题更改时,脚本都会更新,变量标题也会自动更新Applescript在不妨碍脚本其余部分的情况下更新iTunes流标题,applescript,itunes,repeat,Applescript,Itunes,Repeat,我正在使用下面的代码获取当前的iTunes流标题。这很有效。就像我需要的那样,每次iTunes流标题更改时,脚本都会更新,变量标题也会自动更新 repeat tell application "iTunes" set Title to current stream title end tell delay 2 end repeat 但是,由于正在进行的“repeat”功能,脚本的其余部分将不会执行。你知道有什么方法可以在iTunes更改标题时仍然更新变量标题,但不妨碍脚本的其余部分吗?好像它是
repeat
tell application "iTunes"
set Title to current stream title
end tell
delay 2
end repeat
但是,由于正在进行的“repeat”功能,脚本的其余部分将不会执行。你知道有什么方法可以在iTunes更改标题时仍然更新变量标题,但不妨碍脚本的其余部分吗?好像它是在后台运行的?谢谢大家! 解决方案,使用处理程序(处理程序也称为函数、子例程或方法)。 将脚本的其余部分放入处理程序中,从循环中调用此处理程序 像这样:
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