Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSAppleScript突出显示任何具有给定NSRange的Mac应用程序中的文本_Objective C_Macos_Cocoa_Nsapplescript - Fatal编程技术网

Objective c NSAppleScript突出显示任何具有给定NSRange的Mac应用程序中的文本

Objective c NSAppleScript突出显示任何具有给定NSRange的Mac应用程序中的文本,objective-c,macos,cocoa,nsapplescript,Objective C,Macos,Cocoa,Nsapplescript,我试图通过使用NSAppleScript,通过自定义Mac应用突出显示任何Mac应用中的文本。我试过下面的代码,但它不工作 NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"\ tell application \"%@\"\n\ activate\n\ end tell\n\ tell application \"%@\"\n\ set theRang

我试图通过使用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}";

我还有别的办法吗?任何帮助都将不胜感激

这不能适用于所有应用程序,因为在
NSUserDefaults
中指定的应用程序必须具有AppleScript字典,并且该字典必须包含命令、属性和类

许多应用程序根本无法编写脚本,几乎所有应用程序都不理解
创建范围
高亮显示颜色索引

该错误是一个编译错误



从ObjC的角度来看,除非您能解释为什么在这种情况下明确需要KVC,否则不要将
valueForKey:
NSUserDefaults
一起使用。对于
stringForKey:
id
对象
objectForKey:

这不能适用于所有应用程序,因为在
NSUserDefaults
中指定的应用程序必须具有AppleScript字典,并且该字典必须包含命令、属性和类

许多应用程序根本无法编写脚本,几乎所有应用程序都不理解
创建范围
高亮显示颜色索引

该错误是一个编译错误



从ObjC的角度来看,除非您能解释为什么在这种情况下明确需要KVC,否则不要将
valueForKey:
NSUserDefaults
一起使用。有
stringForKey:
id
对象
objectForKey:

1。
tell application
参数是AppleScript编译时的一个文本。@Willeke好的,谢谢,我被占位符弄糊涂了。我澄清了答案。
tell application
参数是AppleScript编译时的一个文本。@Willeke好的,谢谢,我被占位符弄糊涂了。我澄清了答案。提示:在脚本编辑器中测试脚本字符串。@Willeke,它在脚本编辑器中也不起作用。不管怎样,我可以检查哪些关键字在appleScript中适用于哪个应用程序。我有一个参考链接[其中有一个更改文本颜色的示例。但是设置背景颜色/文本选择不起作用。请在脚本编辑器中打开应用程序的字典。提示:在脚本编辑器中测试脚本字符串。@Willeke,在脚本编辑器中也不起作用。我是否可以检查哪些关键字在appleScript中对哪个applic有效我有一个参考链接[其中有一个更改文本颜色的示例。但是设置背景颜色/文本选择不起作用。请在脚本编辑器中打开应用程序的字典。