This is my code (I removed the part that gathers the content for the info variable to make it better readable):
property ScanInfoText : ""
on scanSystem()
set infos to "some text"
set ScanInfoText to infos
end scanSystem
on idle theObject
scanSystem()
tell window of theObject
set contents of text field "total" to ScanInfoText
end tell
return 30
end idle
on clicked theObject
scanSystem()
tell window of theObject
set contents of text field "total" to ScanInfoText
end tell
end clicked
on should quit after last window closed theObject
return true
end should quit after last window closed
As you see the “on clicked” handler has the same script in it as the “on idle” handler, but only the “on clicked” handler works. Why? I just can’t see the logic behind this.
I don’t think the clicked handler is working, but haven’t run your script. Just looking at it, it looks your reference is wrong. Window is an object and you need a reference to it unless there’s a window property. Try it like this:
on idle theObject
scanSystem()
set w to first window of theObject
tell w
set contents of text field “total” to ScanInfoText
end tell
return 30
end idle
or use the window’s name. You can give the window a name in the AppleScript pane of the info palette.
Btw, I’ve taken the clicked handler from an Apple example file (currency converter) and it works perfectly. Just the idle handler doesent work.
Edit: I gave the window a name. The code is now:
on idle theObject
scanSystem()
tell window "mainwindow" of theObject
set contents of text field "total" to ScanInfoText
end tell
return 10
end idle
on clicked theObject
scanSystem()
tell window "mainwindow" of theObject
set contents of text field "total" to ScanInfoText
end tell
end clicked
Still the same thing. The clicked handler works fine, the idle doesent work.
Did you connect the idle event to your application in Interface Builder?
You have to open up the nib file, select “File’s Owner” in the list of objects, and connect “idle” to your script (with the Applescript pane of the Inspector window).
Idle just works in ‘regular’ AS, but you have to explicitly say you’re going to use it in AS Studio.