updating NsTextView

Hi All,

I have this app that does a lot, and it works fine, but I wanted to make a progress window.
But I only get it to work for a while.
I have this progress window that I open at a certain point in the script:

progressWindow's makeKeyAndOrderFront_(me)

And then I output some information to a NSTextView in that window, so that I can see what my script is doing at that point.

set theString to "calculatedDate " & calculatedDate
progressText's setString_(theString)

This works fine. Every step that I make in the script i send a new setString_ command, so I can see the progress off the script. Until a certain point in the script. Then it suddenly stops to work. And that is from the point

tell current application to set theXmlFile to (choose file with prompt "Select the XML file:" of type {"XML"}) as string
		tell application "System Events"
			set theXmlData to XML file theXmlFile
		end tell
				set theString to "finished part 3: opened the XML"
		progressText's setString_(theString)

This “finished part 3: opened the XML” sometimes shows in the NSTextView progressText, but more often it does not. And then I am stuck with the last setString before that. The line does not go blank. It just shows the last one.
But the script continues. It does some XML parsing (tell application “System Events”), without logging to the NSTextView. And then it ends the ‘tell System Events’-part and then it will try to update some new setString_ commands to the NSTextView:

set theString to "boolDateCheck: it is " & boolDateCheck & " that searchDate exists in this XML"
		progressText's setString_(theString)

…then this theString never comes to my progress window.

The script will continue, but none of the setString_ commands will come through. Up until the end of the script:

set theString to "Finished operation in " & theDur & " seconds."
		progressText's setString_(theString)

That last one DOES display.
So how come. Why don’t I see all the setString_ commands in between?
Do I need to update a window manually? Or the NSTextView? And how do I do that in ASOC?
Where could it go wrong, where in the script do I have to search for things that could trigger this behavior?
I hope anybody can help.


At the very least, you need to get the window to update after each change with something like:

tell progressWindow to displayIfNeeded()

Thank you!

Sometimes life is simple.
I am curious about why it did work up until a certain point and then stopped, without the displayIfNeeded command. But whatever the reason is: displayIfNeeded made everything work !
thanks for that.
(I did search and try with setWindowsNeedUpdate, but could not get it to work. Now I know why :slight_smile:

Thanks again

EDIT: repaired a typo.

It depends on what your script is doing. Without displayIfNeeded, it’s a matter of completion of handing the current event. The exact situation can get complex.