我正在尝试通过使用 NSAppleScript 通过自定义 Mac 应用程序突出显示任何 Mac 应用程序中的文本。我试过下面的代码,但它不起作用。
NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"\
tell application \"%@\"\n\
activate\n\
end tell\n\
tell application \"%@\"\n\
set theRange to create range start %ld end %ld\n\
set highlight color index of theRange to %@\n\
end tell\n\
",[[NSUserDefaults standardUserDefaults] valueForKey:@"AppName"],[[NSUserDefaults standardUserDefaults] valueForKey:@"AppName"],(unsigned long)range.location, (unsigned long)(range.location+range.length),@"yellow"]];
但我得到以下错误:
NSAppleScriptErrorBriefMessage = "Expected end of line but found identifier.";
NSAppleScriptErrorMessage = "Expected end of line but found identifier.";
NSAppleScriptErrorNumber = "-2741";
NSAppleScriptErrorRange = "NSRange: {459, 5}";
我还有其他方法可以做到这一点吗?任何帮助将不胜感激。