I would like to use AppleScript Studio to create a script to tell iTunes to reset the finish times of my tracks. I have a big music library and it takes a few minutes for the script to run, so I was hoping to create a progress bar to provide some feedback and a way to cancel/interrupt/break out of the process without waiting for it to finish.
The problem is that when I call the on launch handler, nothing else runs until that script is finished. Is there a way to run scripts, so that I can have other GUI things in my script running and updating as the main script process is doing it’s work? Is there a way for the user to “cancel” a handler?
Essentially I need to start a script to process the iTunes tracks, display a progress bar showing the progress, and allow the user to break out of the process without waiting for it to finish.
Here is what I have so far:
on launched theObject
tell application "iTunes"
set theTracks to every track of the front browser window's view
end tell
set nTracks to count of theTracks
set n to 1
set maximum value of progress indicator "Progress Bar" of window "Progress Window" to nTracks
set content of progress indicator "Progress Bar" of window "Progress Window" to n
set content of text field "Progress Text" of window "Progress Window" to "Reset Finish Times: " & n & " of " & nTracks & " tracks..."
set indeterminate of progress indicator "Progress Bar" of window "Progress Window" to false
set visible of window "Progress Window" to true
repeat with aTrack in theTracks
tell aTrack
try
set {start, finish} of aTrack to {0, -1}
end try
end tell
set content of progress indicator "Progress Bar" of window "Progress Window" to n
set content of text field "Progress Text" of window "Progress Window" to "Reset Finish Times: " & n & " of " & nTracks & " tracks..."
update window "Progress Window"
set n to n + 1
end repeat
end launched
on clicked theObject
quit
end clicked
on should quit after last window closed theObject
return true
end should quit after last window closed