AppleScriptの構文色分けフォーマットをplistから読み込むAppleScriptです。
ただし、本Scriptで取得した色情報はスクリプトエディタ上で設定した内容と若干RGB値が異なるため、色情報をもとに構文要素を判定するような処理に本Scriptをそのまま用いることは推奨しません。
AppleScript名:AppleScriptの構文色分けカラーフォーマットをplistから読み込む |
— Created 2013-11-11 by Shane Stanley — Changed 2014-12-14 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" set cList to getAppleScriptSourceColors() of me –> {{redValue:37265, greenValue:10280, blueValue:37008, fontName:"Osaka", fontSize:13.0}, {redValue:15672, greenValue:3071, blueValue:15832, fontName:"Osaka", fontSize:13.0}, {redValue:3598, greenValue:15934, blueValue:64507, fontName:"Osaka", fontSize:13.0}, {redValue:30840, greenValue:13364, blueValue:52171, fontName:"Osaka", fontSize:13.0}, {redValue:64764, greenValue:10794, blueValue:7196, fontName:"Osaka", fontSize:13.0}, {redValue:0, greenValue:0, blueValue:0, fontName:"Osaka", fontSize:13.0}, {redValue:37265, greenValue:21074, blueValue:4369, fontName:"Osaka", fontSize:13.0}, {redValue:0, greenValue:0, blueValue:0, fontName:"Osaka", fontSize:13.0}, {redValue:10023, greenValue:51657, blueValue:51657, fontName:"Osaka", fontSize:13.0}, {redValue:3855, greenValue:15934, blueValue:64507, fontName:"Osaka", fontSize:13.0}, {redValue:7967, greenValue:46774, blueValue:64764, fontName:"Osaka", fontSize:13.0}, {redValue:33153, greenValue:14906, blueValue:55769, fontName:"Osaka", fontSize:13.0}, {redValue:23901, greenValue:13878, blueValue:37522, fontName:"Osaka", fontSize:13.0}, {redValue:47484, greenValue:3164, blueValue:32926, fontName:"Osaka", fontSize:13.0}, {redValue:6491, greenValue:47213, blueValue:32320, fontName:"Osaka", fontSize:13.0}, {redValue:40001, greenValue:37149, blueValue:1331, fontName:"Osaka", fontSize:13.0}, {redValue:20379, greenValue:0, blueValue:35059, fontName:"Osaka", fontSize:13.0}, {redValue:4539, greenValue:35536, blueValue:35798, fontName:"Osaka", fontSize:13.0}} –AppleScriptの構文色分けのカラー値をRGBで取得する on getAppleScriptSourceColors() — get the info as a dictionary set thePath to current application’s NSString’s stringWithString:"~/Library/Preferences/com.apple.applescript.plist" set thePath to thePath’s stringByExpandingTildeInPath() set theInfo to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath — extract relevant part and loop through set theArray to (theInfo’s valueForKey:"AppleScriptSourceAttributes") as list set colList to {} repeat with i from 1 to count of theArray set anEntry to item i of theArray log anEntry set colorData to NSColor of anEntry set theColor to (current application’s NSUnarchiver’s unarchiveObjectWithData:colorData) set {rVal, gVal, bVal} to retColListFromNSColor(theColor, 65535) of me set fontData to NSFont of anEntry set theFont to (current application’s NSUnarchiver’s unarchiveObjectWithData:fontData) set aFontName to theFont’s displayName() as text set aFontSize to theFont’s pointSize() set aColRec to {redValue:rVal, greenValue:gVal, blueValue:bVal, fontName:aFontName, fontSize:aFontSize} set the end of colList to aColRec end repeat return colList end getAppleScriptSourceColors –NSColorからRGBの値を取り出す on retColListFromNSColor(aCol, aMAX as integer) set aRed to round ((aCol’s redComponent()) * aMAX) rounding as taught in school set aGreen to round ((aCol’s greenComponent()) * aMAX) rounding as taught in school set aBlue to round ((aCol’s blueComponent()) * aMAX) rounding as taught in school if aRed > aMAX then set aRed to aMAX if aGreen > aMAX then set aGreen to aMAX if aBlue > aMAX then set aBlue to aMAX return {aRed, aGreen, aBlue} end retColListFromNSColor |
More from my site
(Visited 74 times, 1 visits today)
AppleScript書類から指定の構文要素をピックアップ(ハンドラ名称) v1 - AppleScript Hole says:
[…] plistから色分け情報を取得してスクリプトエディタ上でattribute runsを取得して照合すると色の数値が合わなくて不思議に思っていました。plistから取り出した値とCocoaの機能を用いてAppleScr […]
AS構文色分け情報の重複チェック - AppleScript Hole says:
[…] plistから読み取ったAppleScriptの構文色分け書式データをもとに、各構文要素の指定色に重複がないかどうかチェックするAppleScriptです。 […]
ぴよまるソフトウェアが選ぶ、2018年に書いた「価値あるScript」 – AppleScriptの穴 says:
[…] ・AppleScriptの構文色分けカラーフォーマットをplistから読み込む これは、Cocoaの機能を使わずに構文色分けフォーマットの判定を行っていた従来バージョンのルーチン(電子書籍のオマケ […]