I am trying to highlight text in any Mac app through may custom Mac app, by making use of NSAppleScript. I have tried below code but it doesn't work.
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"]];
But I am getting below error :
NSAppleScriptErrorBriefMessage = "Expected end of line but found identifier.";
NSAppleScriptErrorMessage = "Expected end of line but found identifier.";
NSAppleScriptErrorNumber = "-2741";
NSAppleScriptErrorRange = "NSRange: {459, 5}";
Is there any other way I can do this? any help will be appreciated.