9 Replies Latest reply: Jun 19, 2012 7:47 AM by red_menace
Drake69 Level 1 Level 1 (0 points)

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, Mac OS X (10.7.4)
  • red_menace Level 6 Level 6 (14,855 points)

    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!

  • Drake69 Level 1 Level 1 (0 points)

    Don't really understand it, like in AppDelegate.h or .m?

    And under or above the text there already is, and things like that.

    But anyway, thanks!

  • red_menace Level 6 Level 6 (14,855 points)

    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.

  • Drake69 Level 1 Level 1 (0 points)

    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

  • Drake69 Level 1 Level 1 (0 points)

    It's a bit unfair I can give myself helpful answer points....

  • HyperNova Software Level 6 Level 6 (8,275 points)

    You can only flag the answer as helpful or solved.

     

    You don't get any points.

  • red_menace Level 6 Level 6 (14,855 points)

    Is the alertWindow property connected, or maybe there are some messages in the debug console that will give a clue?  The values need to be between 0 and 1 (something like 10000 will be seen as 1, which won't be transparent).  The example values I posted work for me - my example project can be downloaded here.

  • Drake69 Level 1 Level 1 (0 points)

    Ok, thanks

     

    But how do you let it 'fade out' & 'in'?

     

    Sorry for my noobyness about Xcode, I just only know applescript, but the Xcode interface editor is so nice...

  • red_menace Level 6 Level 6 (14,855 points)

    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.