Error on calling method

Hello,

Here’s the part of script where i got the error:


on checkMethod_(sender)
        if checkBox's state() = 1 then
            my setUpWork()
        else
            current application's NSApp's beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_
(askForConfirmationPanel, aWindow, me, missing value, missing value)
        end if

on endSheet_(sender)
       current application's NSApp's endSheet_(askForConfirmationPanel)
       askForConfirmationPanel's orderOut_(askForConfirmationPanel)
       my setUpWork()
end endSheet_

on setUpWork()
        --stuff
end setUpWork


So basically there is a checkbox, whose state is saved in Shared User Defaults, and if it has been enabled on the last use or not I get this error after clicking on checkMethod_(sender) ( *** -[AppDelegate endSheet4:]: unable to set argument 2 - the AppleScript value <NSAppleEventDescriptor: ‘msng’> could not be coerced to type d. (error -10000))

I don’t really know what is causing this error, but I think it might be the line my setUpWork().

Any reply would be very appreciated!

–Edited: noticed en error

Hi,

endSheet of NSApplication requires a second parameter returnCode, for example

current application's NSApp's endSheet_returnCode_(askForConfirmationPanel, current application's NSOKButton)

I do notice there are two methods endsheet: and endSheet:returnCode:

I’m afraid it’s not the solution, I still get the same error…

Thanks anyway for the reply :wink:

Unless you show us endSheet4_(), it’s impossible to guess what the problem is.

Oh sorry Shane, stupid me, endSheet4_() is the same as endSheet_()…

First, you shouldn’t use an existing method name unless you match the parameters, so you shouldn’t have endSheet_(sender).

Second, that error message is telling you that some code triggered by calling endSheet4_ is being passed missing value instead of (presumably) an integer or enum. It says argument 2, but sometimes the count is off by one – however, that still suggests the method in question takes more than one parameter. I can’t see that in your code, so it’s hard to know. But calling orderOut_ after endSheet_ looks suspicious anyway.

But you know, if you use my Myriad Helpers this whole business becomes a fair bit easier…

Thanks anyway Shane for the suggest…

However I looked a bit into it and I think the error is definitely in setUpWork() method, because I tried with the following script and both work


on checkMethod_(sender)
if checkBox's state() = 1 then
display dialog "whatever"
else
current application's NSApp's beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_
(askForConfirmationPanel, aWindow, me, missing value, missing value)
end if
end checkMethod_

on endSheet4_(sender)
current application's NSApp's endSheet_(askForConfirmationPanel)
askForConfirmationPanel's orderOut_(askForConfirmationPanel)
display dialog "whatever"
end endSheet4_

…and this


on checkMethod_(sender)
if checkBox's state() = 1 then
my setUpWork()
else
current application's NSApp's beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_
(askForConfirmationPanel, aWindow, me, missing value, missing value)
end if
end checkMethod_

on endSheet_(sender)
current application's NSApp's endSheet_(askForConfirmationPanel)
askForConfirmationPanel's orderOut_(askForConfirmationPanel)
my setUpWork()
end endSheet_

on setUpWork()
        display dialog "whatever"
end setUpWork

------Edit---------

Ok guys I resolved, if I had known what was the meaning of the error maybe I would resolved it a bit before.
Basically I wrote wrong the name of a variable…

Thank you guys anyway, you help has been deeply appreciated!

Everybody has been there, done that:)

This pleases me :wink: