How can I add an additional .nib file to my AS app?

Is there a right and wrong way of adding another .nib file to an AppleScript app?



I am not sure if there is a wrong way but the standard way to do it, per AppleScript Studio documentation, is to open one nib file, usually the “main” nib, and then in the IB, create a new one from the File menu.

You will be prompted with a new option to choose from. Choose “Empty” from the Cocoa option and then go from there. Later on, you will be asked to asked whether you want to add it to your project.

If you want to check further details, go to the Mail program example in AppleScript Studio Programming (can’t remember the exact title but I think you know what I am referring to) which contains multiple nibs. It’ll show you how.

Good luck.

archseed :expressionless:

What’s the benefit of adding a 2nd NIB file?
I’ve always kept adding objects to a single NIB, and although it looks cluttered, it works.
I’m sure there are better reasons to add a 2nd NIB - can anyone enlighten me?

I’m trying two nib’s because I’m not real good at programming applescript yet and was having trouble with having all my code in one nib. I’m not even sure that having the two is going to resolve my problem, but will post when I figure this out.

Also, Apple is using multiple nibs in some of their tutorials.



Actually, Apple’s programming tip (see AppleScript Studio Programmiing Guide) says that multiple nibs are more apt for use when the program becomes big and complex. However, it is not an absolute requirement. If you can wade through the many objects in the IB with one nib file, that is perfectly alright. Otherwise, it is suggested that multiple nibs be used for more manageable organization of complex programs.

Dave, if your program is fairly simple you should have no problem fitting them into one nib and it should work alright.

archseed :slight_smile:

Here are some links that may be of interest:
Loading Resources: Using Multiple Nib Files
AppleScript Studio Terminology Reference: Application Suite

Hello all,

I really appreciate everyones time. I have attached my code for this simple app. Let me first explain what is going on. The app is to simply shutdown the machine at a specific time and do so even if any apps are open with unsaved work (I’m giving plenty of notice for anyone who might be working on the machine, 10 minutes). The app opens with a nice gui and alerts the user with a speaking voice and gives the user the chance to cancel the shutdown by simply clicking the “Cancel” button, other wise the script runs and after 10 minutes does a “shutdown -h now”.

What is going wrong is I can’t get the voice to work properly with the rest of the script. If I include the voice the script gets stuck in it’s flow and seems to disables the rest of the script, this is why I tried to put the voice in a separate .nib, but that doesn’t seem to work either.

Ignore my numbers since their only used for testing purposes.

on awake from nib theObject
	load nib "alert"
	global ToKill, MyName, Del, Del1
	set ToKill to false
	set MyName to do shell script "whoami"
	set Del to false
	set Del1 to true
end awake from nib

on idle theObject
	global ToKill, MyName, Del, Del1
	if Del = true then do shell script "rm -rf /Users/student" password "########" with administrator privileges
	if Del1 = true then do shell script "rm -rf /Library/Caches" password "#######" with administrator privileges
	if ToKill = true then do shell script "shutdown -h now" password "#######" with administrator privileges
	if MyName = "student" then set ToKill to true
	if MyName = "student" then set Del to true
	return 15
end idle

on awake from nib theObject
	repeat until (keys pressed) is {"q"}
		set volume 5
		(say "SHUT DOWN ALERT" using "Victoria")
		delay 5
	end repeat
end awake from nib

Thank you very much!!