Want to ask the user for choosing color from color panel

Hello Everyone,
i am very much new to applescript !!
:lol: All i want to do is to choose a color from color panel in Applescript.I am able to display the color panel, but am not able to set a refernce to the selected color.

Any pointers would be of great help !!

color panel? Then, you must be talking about applescript-studio?
If so, when the user clicks “OK”…

set theColor to color of color panel

If you are really talking about “Mac OS” (pre-X), you can simply install “Jon’s Commands” and use this:

set theColor to (choose color)

thanks jj for the reply.The code you gave didn’t work.Actually,i had tried the same before i had posted the same on this forum.But,you were right when you said that i am trying to build an Applescript Studio application.

The code which i have tried is as follows :


set visible of color panel to true
set mycolor to color of color panel
set background color of window "mainWindow" to mycolor
tell window "mainWindow" to update

The problem with this code is that the chosen color doesn’t get reflected till you invoke the color panel again.Though i have asked the main window to update to the latest chosen color, it doesn’t.Please try to paste it in a small app and see for yourself.

Any help in regards to this would be highly appreciated. Also,can anyone suggest me a good book on Applescript & Applescript Studio as Developer doccumentation is not enough.
:rolleyes:

Oh, no! The code really works, but I start to understand you…

on awake fron nib theobject
     set x to color of color panel
     set background color of theobject to x
end awake

This will change the background color to (by default) white.

What do you wish exactly? Change the background color of the window dinamically?
I’m not sure if it can be done in plain-AS-Studio… You may need some obj-c help to get the color changes in the color panel, since in plain-AS-Studio these are reflected only in the “selection” (eg, selected text).
Also, seems that the color panel doesn’t generate “close” events, so you don’t know when it is opened or not, unless you attach a “idle” handler and check for its visibility periodically.
Eg, if you are working in a preferences window for your app, I’d suggest you put a color-well and an “apply” button, which, on clicked, checks the current color of the color well and applies it to main window’s background.
That’s all I know!

Thanks jj again !!
I think,i got you… Even i agree,there’s no way of knowing the events like “Close” of color panel.So,you can’t trap the color chosen.
thanks for the info.But,i have found a work-around.Actually,in the idle event,i am checking for it and updating the same.

Anyway,thanks for the idea.I am a newbie in Obj C.So,i guess,it would take some time before i acheive the same in Cocoa Obj C.