Search code examples
xcodemacoscocoaapplescript-objccocoa-sheet

Making a sheet from a panel in AppleScriptObjC


Alright, I'm trying to make a sheet appear in my AppleScriptObjC app, based on a panel I've already designed in the 'Interface Builder' .xib file.

I've found a fantastic answer here, but it's for Objective-C, and I'm struggling to translate it into AppleScriptObjC.

Here's the code I've tried at the moment: beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(loadingWindow, mainWindow, me, missing value, missing value)

This just gives me the following error:

[AppDelegate titleRefresh:]: *** -[AppDelegate beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:]: unrecognized selector sent to object <AppDelegate @0x10323d4c0: OSAID(4)> (error -10000)

The original window is called "mainWindow", the panel to be used as a sheet is called "loadingWindow".

If anybody could help me out, that would be really appreciated!


Solution

  • OK, looks like I've managed to figure it out. For anybody else having this issue:

    You need to use the code as below:

    current application's NSApp's beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(loadingWindow, mainWindow, me, missing value, missing value)
    

    …where the Panel you want to use as a sheet is loadingWindow, and the main window (which the sheet will appear over) is mainWindow.

    Similarly, you can close the sheet by using this code:

    current application's NSApp's endSheet_(loadingWindow)
    loadingWindow's orderOut_(loadingWindow)
    

    I hope this helps somebody out there! :)