Well I just thought it might come in handy when working with nibs, eg sub classing or delegates etc. But not necessary of course.
I don’t think you can actually write the library in Xcode since Xcode scripts are class-based and as Shane said, this doesn’t work in libraries. All you’re doing here is creating a dummy project solely for the sake of making connections in the nib, then you can copy the nib into your library.
Eg, your App Delegate might look like this:
script AppDelegate
property myOutlet : missing value
on myAction:sender
end myAction
end script
Then in the nib you set the class of File’s Owner to “AppDelegate” so you can connect your outlets and actions to it.
I’ve been playing around a bit with this nib loading stuff and have a problem where if I show the window using makeKeyAndOrderFront: (in a stay-open app) the window is completely unresponsive, even for mousing over the close widgets. I can make it work using modal instead but was hoping someone might have an idea of why this problem happens.
Using loadNibNamed with connections set in the nib. I’ve tried a few different ways though, such as init/instantiate and using an object enumerator instead of connections, all do the same thing.
property testWindow : missing value
on showWindow()
set myBundle to my (NSBundle's bundleWithPath:(POSIX path of (path to me)))
myBundle's loadNibNamed:"MainMenu" owner:me topLevelObjects:(missing value)
testWindow's makeKeyAndOrderFront:(null)
end showWindow
I made a nib called Test.nib. It contains a window, and the window has a button with an action of doIt: targeted at First Responder. I added it to the Resources folder of a lib containing the following:
use scripting additions
use framework "Foundation"
use framework "AppKit"
on showWindow()
set myBundle to my (NSBundle's bundleWithPath:(POSIX path of (path to me)))
set {theResult, theArray} to myBundle's loadNibNamed:"Test" owner:me topLevelObjects:(reference)
set theWindow to theArray's objectAtIndex:0
theWindow's makeKeyAndOrderFront:(null)
end showWindow
on doIt:sender
display dialog "Here"
end doIt:
I then called the script using:
use theLib : script "With nib"
theLib's showWindow()
The dialog appears, and when I hit the button, the “Here” dialog appears.
How are you running the script?
I just tried exactly what you’ve done there and found the window was responsive if I just clicked “run” in Script Editor, but when I save as a “stay-open” applet and launch the applet it again wouldn’t respond.
P.S. How did you connect a custom action to First Responder?
For reference, I encountered a similar problem when checking out the sample script library from your website which created a window with a progress bar. Worked fine within script editor, but when saved as an applet it gave me this error when it tried to order in the window: Error (1000) creating CGSWindow on line 263
Again, doing a “display alert” beforehand avoided the problem.
Well yes, that allows the “choose file” to avoid the problem, which is fine, but I’m wondering why the problem happens and if it can be avoided without showing some sort of UI from standard additions beforehand. Not a big deal, I’m fine with using “display alert” to avoid it for now, I’m just curious