Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to create an 'Apple sound popup' in Xcode?

Hello,


When you set your volume harder (on a mac), there displays a nice, litte, a bit transparant, pop-up.

Is there a way to create such a pop-up?

I try to do it with applescript (inside xcode).

Xcode itself has also a pop-up like that, if you try to run your app, it display a pop-up

"Built succeeded", (or a hated pop-up "Built failed").


Kind regards,


Isaiah


P.S. I'm a noob in Xcode, so is there a way I just add a button, and connect it (with control-click, and drag) to for example "File owner", and then click "Pop-up effect"?

Xcode-OTHER, Mac OS X (10.7.4)

Posted on Jun 16, 2012 7:27 AM

Reply
Question marked as Best reply

Posted on Jun 16, 2012 1:58 PM

The ones you are talking about most likely use a custom view over a transparent background, with some custom objects and animations thrown in there for good measure. Since you are a noob and all 😉, there is a little bit easier way to make a simple dialog that avoids having to create the rounded corner background and code the animations and all.


In your AppDelegate or controller script, add an outlet for the alert window:


property alertWindow : missing value



Add an action handler for the button:


on showAlert_(sender)

-- add additional setups or animations as desired

alertWindow's orderFront_(me)

performSelector_withObject_afterDelay_("hideAlert", me, 5) -- close after delay

end showAlert_



And add another handler to hide the window:


on hideAlert()

-- add additional setups or animations as desired

alertWindow's orderOut_(me)

end hideAlert



In the Interface Editor, create another window for your dialog (I use a regular window, since the panels are a bit too dark) and connect the window (not the view) to your alert outlet using the Connections Inspector or equivalent shortcut. Uncheck the "Visible at Launch" option, and make the window animation "Inspector Panel Style" to slow down the (dis)appear time a bit.


Add labels for your alert text (make the text white) and whatever other items and positioning you want. Add/connect whichever button you are wanting to use in your main application window to your action handler, and you are just about ready to go.


You will need to do some additional setup for the alert window to make it gray and partly transparent, so somewhere such as in the AppDelegate's applicationWillFinishLaunching_ handler add the following:


alertWindow's setOpaque_(false)

alertWindow's setBackgroundColor_(current application's NSColor's colorWithCalibratedWhite_alpha_(0.0, 0.5))


In that last statement, the first number sets the grayscale, and the second is the opacity - tweak as desired.


Good Luck!

9 replies
Question marked as Best reply

Jun 16, 2012 1:58 PM in response to Drake69

The ones you are talking about most likely use a custom view over a transparent background, with some custom objects and animations thrown in there for good measure. Since you are a noob and all 😉, there is a little bit easier way to make a simple dialog that avoids having to create the rounded corner background and code the animations and all.


In your AppDelegate or controller script, add an outlet for the alert window:


property alertWindow : missing value



Add an action handler for the button:


on showAlert_(sender)

-- add additional setups or animations as desired

alertWindow's orderFront_(me)

performSelector_withObject_afterDelay_("hideAlert", me, 5) -- close after delay

end showAlert_



And add another handler to hide the window:


on hideAlert()

-- add additional setups or animations as desired

alertWindow's orderOut_(me)

end hideAlert



In the Interface Editor, create another window for your dialog (I use a regular window, since the panels are a bit too dark) and connect the window (not the view) to your alert outlet using the Connections Inspector or equivalent shortcut. Uncheck the "Visible at Launch" option, and make the window animation "Inspector Panel Style" to slow down the (dis)appear time a bit.


Add labels for your alert text (make the text white) and whatever other items and positioning you want. Add/connect whichever button you are wanting to use in your main application window to your action handler, and you are just about ready to go.


You will need to do some additional setup for the alert window to make it gray and partly transparent, so somewhere such as in the AppDelegate's applicationWillFinishLaunching_ handler add the following:


alertWindow's setOpaque_(false)

alertWindow's setBackgroundColor_(current application's NSColor's colorWithCalibratedWhite_alpha_(0.0, 0.5))


In that last statement, the first number sets the grayscale, and the second is the opacity - tweak as desired.


Good Luck!

Jun 17, 2012 8:20 AM in response to Drake69

For an AppleScript project in Xcode, the application delegate will have an .applescript extension, such as AppDelegete.applescript. If you have AppDelegate .h and .m files, you are either talking about a regular Cocoa Application, or are using the wrong project template for an AppleScript application.


For some basic information about AppleScript applications in Xcode using AppleScriptObjC, see the tutorials at MacScripter, and Shane Stanley's AppleScriptObjC Explored is pretty much the only guide out there.

Jun 18, 2012 8:24 AM in response to red_menace

Thanks, but the opacity setting won't work: even if I set the 'greyscale & opacity numbers' to

'0.5, 1000000.5' it isn't a bit transparant.


This is my appdelegate; maybe it helps:


script AppDelegate

property parent : class "NSObject"

property alertWindow : missing value

on applicationWillFinishLaunching_(aNotification)

alertWindow's setOpaque_(false)

alertWindow's setBackgroundColor_(current application's NSColor's colorWithCalibratedWhite_alpha_(0.5, 1000000.5))

--default first number is 0.8

end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)

-- Insert code here to do any housekeeping before your application quits

return current application's NSTerminateNow

end applicationShouldTerminate_

on showAlert_(sender)

-- add additional setups or animations as desired

alertWindow's orderFront_(me)

performSelector_withObject_afterDelay_("hideAlert", me, 3) -- close after delay

end showAlert_

on hideAlert()

-- add additional setups or animations as desired

alertWindow's orderOut_(me)

end hideAlert

end script

Jun 19, 2012 7:47 AM in response to Drake69

As I mentioned in my first post, there are a few default animations you can use for the window, but to do anything more you are going to need to use the QuartzCore framework and Core Animation with a custom view. Those topics are not all that noobish, especially since the references and examples are in Objective-C. It can be done though - a couple of projects I'm working on use animations, so eventually I'll have some examples using the classes.

How to create an 'Apple sound popup' in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.