I want to display a dialog box with 2 buttons. If one button is clicked my application launches as normal. If the other button is clicked I have some text written to a text file and then the application quits or does not launch.
I tried putting it in the “on applicationWillFinishLaunching_(aNotification)” and the dialog would appear but if I clicked the button to quit my app still launched. I tried a couple of other things and I am now getting this output in the debugger console :
History Revision(4669) malloc: recording malloc stacks to disk using standard recorder
History Revision(4669) malloc: process 4597 no longer exists, stack logs deleted from /tmp/stack-logs.4597.History Revision.hTp7jZ.index
History Revision(4669) malloc: stack logs being written into /tmp/stack-logs.4669.History Revision.MGHkkI.index
And the dialog box does not come up but the app launches. Could someone give me a hint on the best way to do this?
I am putting this in the applicationWillFinishLaunching_ script
on applicationWillFinishLaunching_(aNotification)
if button returned of (display dialog "What is the status?" buttons {"Done","Processing"} with title "Job Status") is "Done" then
-- quit
current application's NSApp's terminate_(me)
-- return current application's NSTerminateNow
end if
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
At one time it would launch but the app still opened. Now the app launches without the dialog even coming up. I tried putting in the “current application’s NSApp’s terminate_(me)”. No difference. If Processing is clicked I would like the app to launch.
I added a panel and made it look like a dialog box. How do I get this to come up first before the main program and have it prevent the launching of the main program if need be.
Sorry if this is simple but I am an Applescripter and this is my first shot at xcode using Applescriptobj-c.
I tried what you suggested and the dialog doesn’t even appear. I gave up on the display dialog. Something just didn’t seem right doing it that way.
I have since made a NSPanel (utility as modal) which I am using as a dialog. I have tried different types of bindings with mixed results. Sometimes the NSPanel will appear by itself and if I click the “Done” button it quit the application all together( it should ). Then if I try to launch it again by choosing run without building the dialog appears with the main application behind it. I can choose what I want in the dialog and it will work the way it should but I do not want the main application behind it. If I click the “Processing” button and let it go through its motions. The next time I choose run without building, just the dialog appears first.
on applicationDidFinishLaunching_(aNotification)
set response to button returned of (display dialog "do you want to quit?" buttons {"yes","no"} default button "no")
if response as string is "yes" then
try
tell me to quit
on error quittingError
log "error is: " & quittingError
end try
end applicationDidFinishLaunching_
The dialog does pop up but my application launches before I can click anything. This is why I though I would switch to the NSPanel and make a dialog of it. I want the dialog to come up before the application appears on the screen. Then what ever the user chooses will depend on if the application will open and show itself or everything just quits.
I have the NSPanel working but it is inconsistent. Sometimes it will come up by itself, which is good. Other times it will come up in front of the application but it is not the window with the focus and within maybe 30 seconds it disappears. If I could at least make it the frontmost window when the application shows itself behind it, that would be okay. I think I have binding problems between the NSPanel and the NSWindow of the app.
My MainMenu.xib has both the NSPanel (dialog) and the NSWIndow(application) in it and the are both using the same App App Delegate. I do not know if that makes a difference or not.
If you want your dialog to appear, then your application has to launch. If you call “application launches” the fact that your main window come on the screen, why don’t you uncheck the “visible at launch” option of this main window?
Hi Fiz,
I tried that under Behavior for the main window turning visible at launch off. When I click the button processing in my dialog the dialog goes away as it should and then nothing happens. When I click the button processing how would I call the main application to become visible? Before I was just leaving it empty and it would open. I am not sure how to call it.
Now I should have the Behavior for myMainWindow set to invisible at launch off, and I should put this code in my processing button so when I click it my NSPanel (dialog) closes and my main program opens. This is what I get when I do that:
unrecognized function makeKeyAndOrderFront_. (error -10000)
Should it be like make window visible or something like that. Although I didn’t see anything like that in the header file for NSWindow.
The identifier for the NSWindow in my program is myMainWindow under the drop down “User Interface Item Identifier”
An identifier is not a property. A property is declared like this, at the beginning of your main script:
property myMainWindow : missing value – in IB, you bind this property to your main window.
.
.
on applicationWillFinishLaunching_(aNotification)
if button returned of (display dialog “What is the status?” buttons {“Done”,“Processing”} with title “Job Status”) is “Done” then
– quit
current application’s NSApp’s terminate_(me)
– return current application’s NSTerminateNow
end if
It does exactly what I want. Only my NSPanel shows up without the application window behind it. When I click the processing button the application launches.
I couldn’t have gotten this far without all your suggestions. Thank you very much.
Rich
It didn’t seem right where I was putting the line of code you sent. This is my first xcode program. I have worked with Applescript and Java in the past.
makeKeyAndOrderBack does not exist (or it is a handler that you created). Do you mean:
myMainWindow’s orderOut_(me) – makes the window invisible.
A window which is “key” (first to receive events) and placed in the background. sounds bad, don’t you think?
I’m not sure the problem is in your code. It must be in the bindings. I recommend to you, if you haven’t yet purchased it, the book of Shane Stanley, it’s the best (and in fact the only one) book on ApplescriptObjC.
ASOC is a big step to do alone. This book has certainly helped me a lot (and the guys of MacScripters, a lot too).
While I was in xcode the main window was not showing up. Once I archived it the main window is showing up but it is in the background and my dialog is set to the foreground. Before this code was added the dialog would appear in front of the main program but the main program was selected not the dialog. So the dialog would disappear after about 30 sec. With this code added the dialog is selected and the main program is not so the dialog does not disappear at all.
It is not exactly what I wanted but i am told it will be okay. I already created the NSPanel and started using that before you sent the code for the full dialog. When I am allowed the time I will disable the NSPanel and try it with the code you sent.
No I did not create it. I just took a chance and changed it. It will work for now I guess.