03/07 テキストへの色指定サンプル
テキストに色指定を行うサンプルのAppleScriptObjCプログラムです。

| AppleScriptObjCファイル名:textcolorTestAppDelegate.applescript |
| – – textcolorTestAppDelegate.applescript – textcolorTest – – Created by 長野谷 隆昌 on 12/02/13. – Copyright 2012 Piyomaru Software. All rights reserved. – script textcolorTestAppDelegate property parent : class "NSObject" property nsc : class "NSColor" property tf : missing value property aTextField : missing value on applicationWillFinishLaunching_(aNotification) –ひとつめのNSTextField(入力フィールド) set aString to current application’s NSMutableAttributedString’s alloc()’s initWithString_("これはテスト用の文字列ですよー") set colorArray to current application’s NSArray’s arrayWithObjects_(nsc’s redColor(), nsc’s orangeColor(), nsc’s yellowColor(), nsc’s greenColor(), nsc’s blueColor, nsc’s purpleColor(), missing value) repeat with i from 0 to (aString’s |length|()) - 1 aString’s addAttribute_value_range_(current application’s NSForegroundColorAttributeName, colorArray’s objectAtIndex_(i mod 6), {i, 1}) end repeat tf’s setAttributedStringValue_(aString) –ふたつめのNSTextField(Label) set bString to current application’s NSMutableAttributedString’s alloc()’s initWithString_("●私のユーザー名") set colorArray to current application’s NSArray’s arrayWithObjects_(nsc’s redColor(), nsc’s blackColor()) set bLen to bString’s |length|() bString’s addAttribute_value_range_(current application’s NSForegroundColorAttributeName, colorArray’s objectAtIndex_(0), {0, 1}) bString’s addAttribute_value_range_(current application’s NSForegroundColorAttributeName, colorArray’s objectAtIndex_(1), {1, (bLen - 1)}) aTextField’s setAttributedStringValue_(bString) end applicationWillFinishLaunching_ on applicationShouldTerminate_(sender) return current application’s NSTerminateNow end applicationShouldTerminate_ end script |


