Inserting text into a new Window

Hi Everybody
I am new to AppleScriptStudio.
I try to write a little program that will take a text file and will copy files from one folder to another. At the end it will open a new window
with a list of all the files it couldn’t find.
I created 2 .nid fils and use on Applescript.
The first nib file is the mainmenu.nib - the place to specify the text file and 2 folders.
The second nib is the Report.nib - the window containing a test view and 2 buttons, Print & Save.
the problem is the Set Contents comand.
I always get that message: “NSCannotCreatScriptCommandError(10)”.
Here is the part of the script that create the Report window and setting the content of the text view.

another problem is it will not open the window with the specified name. But that is not as important.

on openReport()
openReportWindow()
end openReport

on openReportWindow()
set ReportWindow to makeReportWindow()
tell ReportWindow
set visible to true
set reportContents to “Run Forrest Run”
set theSubject to “Subject”
set contents of text view “Report” of scroll view ¬
“Report” to reportContents
set title to theSubject
set visible to true
end tell
end openReportWindow

on makeReportWindow()
load nib “Report”
set windowName to “Missing Coupons” & windowCount
set name of window “Report” to windowName
return window windowName
end makeReportWindow

thank you all

Greetings yarnin. You’re making this way more complicated than it needs to be.

First, with an app of this size and complexity… or rather lack thereof… you should not need two nib files. You can add a window to your mainmenu.nib by dragging a window from the objects palette to your nib in interface builder. This will eliminate the extra overhead of a second nib, and make it a bit easier to manage your objects. Make sure to name it “Report” in the applescript pane of the info window, not in the title field of the attributes pane.

Second, you are confusing the “name” property and the “title” property. If you change the name of an object, and then try to reference it, it will of course not exist! The name is found in the applescript pane in the info window in IB. This is what applescript uses to identify the window, and is very important. You should NOT get in the habit of changing an object’s name without having a clear knowledge of how to keep track of changes you make. The title is what is displayed in the title bar at the top of the window. This can be anything, or nothing… and will rarely effect your application, other than aesthetically.

As I see it, you should only need something similar to the following to get the job done…

on openReport()
	tell window "Report"
		set windowCount to 5 --> for testing
		set title to ("Missing Coupons: " & windowCount) as string

		set reportContents to "Run Forrest Run"
		set contents of text view "Report" of scroll view "Report" to reportContents

		show --> display's the window (use 'hide' to hide it)
	end tell
end openReport 

Good luck…
j

Hi jobu
Thank you very mach for your answer.
It made things much easier and simple. Now I get the name of the window (Title) wright, but still got some problem with the “text view”.
When I try to use the format you’ve written I get this message: “NSReceiverEvaluationScriptError: 4 (1)”.
When I add to the window the “became main” command, for easier scripting later on regarding that window and object in it, and then try to set the content of the “text view”
I get this message: “NSCannotCreateScriptCommandError (10)”.
So I tried to for the command like this “set contents of text view “Report” of scroll view of theObject to reportContents”,
and then I got this message: “NSReceiverEvaluationScriptError: 4 (1)”.

Can you tell my where and what is the problem?

Thank you

The error you’re getting is usually a sign that you have not named an object correctly, or not named it at all. One thing about text views, is that they are automatically placed within a scroll view when you drag them to the window. When you click on the text view once, it is highlighted with blue dots all around it. This is actually the scroll view that is selected, not the text view itself. You need to double click on the text view again, to get the text view selected (blue lines all around). Make sure both are named “Report” assuming that you’re still using the nameing scheme from your first post.

If this is not the problem, go through all of your objects again and make sure that theye are named properly, remembering that case is important.

j

Thank you very mach - It works.