Reputation: 326
I am using the code below to get the current iTunes stream title. That works great. Just like I need it to be, the script updates every time when the iTunes stream title changes, the variable Title updates itself as well.
repeat
tell application "iTunes"
set Title to current stream title
end tell
delay 2
end repeat
However, because of the ongoing "repeat" function, the rest of the script will not execute. Do you know of any way to still get the variable Title to be updated when iTunes changes its title, but not obstruct the rest of the script? As if it sort of runs in the background? Thank you!
Upvotes: 1
Views: 112
Reputation: 7191
A solution, use an handler (Handlers are also known as functions, subroutines, or methods). Put the rest of the script in an handler, call this handler from the loop.
Like this :
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
Upvotes: 1