Is it possible to predefine constant or variable for an AppleScript in cocoa application?
in other words is the function “addConstantToAppleScript” (used in the following code) definable?
addConstantToAppleScript("myText", "Hello!");
char *src = "display dialog myText";
NSString *scriptSource = [NSString stringWithCString:src];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:scriptSource];
NSDictionary *scriptError = [[NSDictionary alloc] init];
[appleScript executeAndReturnError:scriptError];
thanks.
If you want to prepend an
NSDictionaryof key/value pairs to the beginning of anNSStringcontaining AppleScript you could use something like the following function. Personally I would do this as a category on NSString but you have asked for a function.This function converts the key/value pairs to AppleScript statements of the form
set <key> to "<value>". These statements are then added to the front of the suppliedscriptstring. The resulting script string is then returned.You would use the above function as follows: