Prompting for a Color
Use the Standard Additions scripting addition’s choose color command to ask the user to select a color from a color picker dialog like the one shown in Figure 29-1. The command accepts an optional default color parameter, and produces an RGB color value as its result. Listing 29-1 and Listing 29-2 display a color picker, create a TextEdit document containing some text, and apply the chosen color to the text.
APPLESCRIPT
set theColor to choose color default color {0, 65535, 0}--> Result: {256, 40421, 398}tell application "TextEdit"set theDocument to make new documentset text of document 1 to "Colored Text"set color of text of document 1 to theColorend tell
JAVASCRIPT
var app = Application.currentApplication()app.includeStandardAdditions = truevar color = app.chooseColor({defaultColor: [0, 1, 0]})// Result: [0.003753719385713339, 0.7206835746765137, 0.005828946363180876]color = [Math.trunc(color[0] * 65535), Math.trunc(color[1] * 65535), Math.trunc(color[2] * 65535)]var textedit = Application("TextEdit")var document = textedit.make({new: "document"})document.text = "Colored Text"document.text.color = [256, 40421, 398]
Prompting for a Choice from a List
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-06-13
