【问题标题】:Working with NSWindow and NSTextview view using ApplescriptObjc使用 ApplescriptObjc 处理 NSWindow 和 NSTextview 视图
【发布时间】:2019-06-16 21:59:00
【问题描述】:

感谢 red_menance 和 CJK,我编写了一些 ApplescriptObjc 代码。我做了一些更改,将其变成一个处理程序并弄清楚如何在 NStextview 中更改字体和字体大小,但是我在通过变量更改字体颜色和背景颜色时遇到了麻烦。

我正在尝试传递一个变量值,但看起来变量名被视为文字。那么如何让它接受变量值呢?这只是代码的 sn-p,如果有帮助,我可以发布整个脚本。

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» 的 textColor 设置为 NSColor 的颜色。

【问题讨论】:

    标签: appkit foundation applescript-objc


    【解决方案1】:

    您可以使用key value coding通过字符串参数访问属性,例如:

    set theColor to "red"
    set theColor to (theColor & "Color")
    set its textColor to (current application's NSColor's valueForKey:theColor)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多