call method “newDocument:”


I have a Document based application in which I want to programmatically make a new document.

The menu option “New File” calls “newDocument:” so I figured i would just be able to do call method “newDocument:” i my script, but that won’t work.

Any ideas on this?


after doing some reading I’ve come to this:

call method “newDocument:” of ___ with parameter “my title”

what should be in the blank space? is it of a class (NSDocument) or is it of a obj (my app)?


if you have a document based application you actually don’t have to do anything.
In MainMenu.xib the menu item New is connected to First Responder with the newDocument: method
which opens a new document specified in Document.xib

yes, I know. But I don’t want the user to be able to do that.
I want to make a new document programmatically.

Thank you! :smiley:

Do you know if it’s possible to sent a title with that call. I’m trying to avoid the “should open untitled” event handler.

on will finish launching theObject
	(*"Called from the application object just prior to completion of launching."*)
	set controllers to {}
	set folder_items to list folder mac_path without invisibles
	repeat with an_item in folder_items
		if an_item ends with ".pdf" then
			call method "performActionForItemAtIndex:" of object (menu 2 of main menu) with parameter 0 -- 0 = first menu item
			set title of (window of first document) to an_item
		end if
	end repeat
end will finish launching

This code goes in a loop since the call method command triggers the on will finish launching event handler.
I thought that this event handler set in File Owner only was triggered when the actual application was launched. It isn’t triggered when i manually create a new window, just when i use the call method.

Why is this? Anybody?

Very strange.
If I for example do call method from within a “on clicked” event handler it doesn’t run “on will finish launching” again. It’s just when the call from that specific handler.

as far as I know, the will finish launching handler is only affected by (NS)application,
that means, it will be called once (if enabled) at the end of the application launching process