[AppleScript]HexColorPicker(Finderスクリプト)
set theDisptext to "" as Unicode text
set theRGB16bitColor to "" as list
set theRdec to "" as integer
set theGdec to "" as integer
set theBdec to "" as integer
set theRhex to "" as text
set theGhex to "" as text
set theBhex to "" as text
-------RGB16bitColorに16bitRGB値を格納
set the theRGB16bitColor to (choose color default color {0, 0, 0}) as list
--------リスト形式で取得したカラー値をRGBに振り分け
set theRdec to (item 1 of theRGB16bitColor) / 256 div 1 as integer
set theGdec to (item 2 of theRGB16bitColor) / 256 div 1 as integer
set theBdec to (item 3 of theRGB16bitColor) / 256 div 1 as integer
------RGB毎の DEC値をHEX値に変換 ゼロサプレスしてから英字を大文字へ変換
set theRhex to do shell script "printf \"%02x\\n\" " & theRdec & " | tr \"a-z\" \"A-Z\"" as string
set theGhex to do shell script "printf \"%02x\\n\" " & theGdec & " | tr \"a-z\" \"A-Z\"" as string
set theBhex to do shell script "printf \"%02x\\n\" " & theBdec & " | tr \"a-z\" \"A-Z\"" as string
------#を付けてHTML用のHEXカラーコードに
set theDisptext to "#" & theRhex & theGhex & theBhex as Unicode text
------ダイアログ表示用のテキスト
set theRGB8bitColor to "R:" & theRdec & " G:" & theGdec & " B:" & theBdec as Unicode text
tell application "Finder"
-----------------ファインダ アクティブ
activate
-----------------ダイアログ表示
display dialog "RGB:" & theRGB8bitColor & " のHEXカラーが\n出来ました\nコピーして使って下さい。" default answer the theDisptext with icon 1 with title "コードをコピーしてください" default button 1
end tell
| 固定リンク
「AppleScriptColor」カテゴリの記事
- [AppleScript]HexColorPicker(Finderスクリプト)(2012.02.06)
- [choose color]色を取得する(2010.07.27)