the following line does not work with in iTunes tell block:
tell application “itunes”
do some stuff
set ts to “some string”
set contents of text field “status2” of tab view item “actions” of tab view “maintabs” of window “main” to ts
end tell
it gives me an error at compile time in XCode.
Also, this does not compile in the same tell block:
tell me to set contents of text field “status2” of tab view item “actions” of tab view “maintabs” of window “main” to ts
putting it outside the tell block works.
putting it in a subroutine, and calling that subroutine from within the iTunes tell block compiles, but does nothing at run time. ie,
on showstatus2(ts)
set contents of text field “status2” of tab view item “actions” of tab view “maintabs” of window “main” to ts
end showstatus2
i have no easy way to escape from that tell block. any ideas what’s going on or how to solve it?
Have you tried declaring ts as a property at the top level of the script?
property ts : ""
tell application "iTunes"
--do some stuff
set ts to "some string"
my showstatus2(ts)
end tell
on showstatus2(ts)
set contents of text field "status2" of tab view item "actions" of tab view "maintabs" of window "main" to ts
end showstatus2
(Note: this solution is untested; I’ve got too much going on in AppleScript Studio at the moment. )
setting ts as a property seemed to have had some effect in getting the status message to appear eventually, but the timing is way off. the program seem to go way beyond the points it is supposed to show a status message. it’s rather strange.
sorry but how do you tell the window, or a text view, or a progress bar, to update? (other than just setting the new value).
The parts of these routines that I’m trying to “update” return errors (the rest don’t):
on doprog(v)
if v = 1 then
tell tab view item “actions” of tab view “maintabs” of window “main” to start progress indicator “prog”
else if v = 0 then
tell tab view item “actions” of tab view “maintabs” of window “main” to stop progress indicator “prog”
else
tell tab view item “actions” of tab view “maintabs” of window “main” to set content of progress indicator “prog” to v
end if
–tell tab view item “actions” of tab view “maintabs” of window “main” to update progress indicator “prog”
return true
end doprog
on showstatus2(ts)
tell me
set contents of text field “status2” of tab view item “actions” of tab view “maintabs” of window “main” to ts
–tell (text field “status2” of tab view item “actions” of tab view “maintabs” of window “main”) to update
–tell window “main” to update
end tell
end showstatus2
Here is some code I’ve used before that does an update -
tell window "mainWindow"
tell progress indicator "progressSpinner" to start
set contents of text field "progressLabel" to "Preparing files..."
update
end tell
on idle theObject
tell application "System Events"
set iTunes to ((application processes whose (name is equal to "iTunes")) count)
end tell
if iTunes is greater than 0 then
try
using terms from application "iTunes"
tell application "iTunes" to get player state as string
end using terms from
if result is not "stopped" then
tell application "iTunes"
set j to (duration of current track) / 60 as string
set k to (player position) / 60 as string
end tell
update_progress(k, j)
end if
on error
return ""
end try
end if
return 1
end idle
on update_progress(iteration, total_count)
tell window "mainWindow"
if iteration = 0 then
tell progress indicator "progress" to start
set indeterminate of progress indicator "progress" to true
else
tell progress indicator "progress" to stop
set indeterminate of progress indicator "progress" to false
end if
set maximum value of progress indicator "progress" to total_count
set content of progress indicator "progress" to iteration
update
end tell
end update_progress
It updates the progress every second. Hopefully that helps
and as for your first question, try:
tell application "itunes"
do some stuff
set ts to "some string"
set contents of text field "status2" of view of tab view item "actions" of tab view "maintabs" of window "main" to ts
end tell
adding “of view” should make it work properly.
as for putting it in a subroutine, try
on showstatus(ts)
tell window "main"
set contents of text field "status2" of view of tab view item "actions" of tab view "maintabs" to ts
end tell
end showstatus
I think I had it worked out already, but thanks for this. In particular the idea to tell window “main” to update within the idle handler is a good one, and should help with the interface lag I think.