使用 ApplescriptObjc 使用 NSWindow 和 NSTextview 视图
Working with NSWindow and NSTextview view using ApplescriptObjc
我有一些 ApplescriptObjc 代码,感谢 red_menance 和 CJK。我做了一些更改,使其成为一个处理程序并弄清楚如何更改 NStextview 中的字体和字体大小,但我 运行 遇到了通过变量更改字体颜色和背景颜色的麻烦。
我正在尝试传递一个变量值,但看起来变量名被当作了文字。那么如何让它接受变量值呢?这只是代码片段,如果有帮助,我可以 post 整个脚本。
set theColor to "white"
set theBackgroundcolor to ""
if theColor is "" then
set its textColor to (current application's NSColor's whiteColor)
else
set theColor to (theColor & "Color") as string
set its textColor to (current application's NSColor's theColor)
end if
if theBackgroundcolor is "" then
set its backgroundColor to (current application's NSColor's grayColor)
else
set theBackgroundcolor to (theBackgroundcolor & "Color") as string
set its backgroundColor to (current application's NSColor's theBackgroundcolor)
end if
我得到的错误是:
无法将 «class ocid» id «data optr00000000E0F1320080600000» 的背景颜色设置为 NSColor 的背景颜色。
和
无法将 «class ocid» id «data optr00000000E029320080600000» 的文本颜色设置为 NSColor 的颜色。
您可以使用 key value coding 通过字符串参数访问属性,例如:
set theColor to "red"
set theColor to (theColor & "Color")
set its textColor to (current application's NSColor's valueForKey:theColor)
我有一些 ApplescriptObjc 代码,感谢 red_menance 和 CJK。我做了一些更改,使其成为一个处理程序并弄清楚如何更改 NStextview 中的字体和字体大小,但我 运行 遇到了通过变量更改字体颜色和背景颜色的麻烦。
我正在尝试传递一个变量值,但看起来变量名被当作了文字。那么如何让它接受变量值呢?这只是代码片段,如果有帮助,我可以 post 整个脚本。
set theColor to "white"
set theBackgroundcolor to ""
if theColor is "" then
set its textColor to (current application's NSColor's whiteColor)
else
set theColor to (theColor & "Color") as string
set its textColor to (current application's NSColor's theColor)
end if
if theBackgroundcolor is "" then
set its backgroundColor to (current application's NSColor's grayColor)
else
set theBackgroundcolor to (theBackgroundcolor & "Color") as string
set its backgroundColor to (current application's NSColor's theBackgroundcolor)
end if
我得到的错误是: 无法将 «class ocid» id «data optr00000000E0F1320080600000» 的背景颜色设置为 NSColor 的背景颜色。 和 无法将 «class ocid» id «data optr00000000E029320080600000» 的文本颜色设置为 NSColor 的颜色。
您可以使用 key value coding 通过字符串参数访问属性,例如:
set theColor to "red"
set theColor to (theColor & "Color")
set its textColor to (current application's NSColor's valueForKey:theColor)