在 obj-c 中向 applescript 添加变量
Adding a variable to applescript within obj-c
不确定在 objective-c 中是否可以在不将脚本作为文件的情况下使用 运行 那样。
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:@\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
end timeout \n \
end tell \n \
end tell"];
这很好用,但我想做的是用字符串替换 "Demo Window 1"(因为它将在程序中动态更改)
当我使用这样的东西时
NSString *windowName = @"Green Window4";
然后替换这一行:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
有:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%@" \n \
和
end tell", windowName];
我收到一个错误,提示参数太多,有没有办法在不分开脚本的情况下执行此操作?
像这样构建字符串;
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:
[[NSString alloc] initWithFormat:@\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%@" \n \
end timeout \n \
end tell \n \
end tell", windowName]
];
或者将字符串构建为一个单独的步骤以提高可读性。
不确定在 objective-c 中是否可以在不将脚本作为文件的情况下使用 运行 那样。
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:@\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
end timeout \n \
end tell \n \
end tell"];
这很好用,但我想做的是用字符串替换 "Demo Window 1"(因为它将在程序中动态更改)
当我使用这样的东西时
NSString *windowName = @"Green Window4";
然后替换这一行:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"Demo Window 1" \n \
有:
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%@" \n \
和
end tell", windowName];
我收到一个错误,提示参数太多,有没有办法在不分开脚本的情况下执行此操作?
像这样构建字符串;
NSAppleScript *appleScriptGetHH = [[NSAppleScript alloc] initWithSource:
[[NSString alloc] initWithFormat:@\
"tell application \"System Events\"\n \
tell process \"Grabee\"\n \
with timeout of 0 seconds\n \
get value of attribute \"AXValue\" of text area 1 of scroll area 1 of window \"%@" \n \
end timeout \n \
end tell \n \
end tell", windowName]
];
或者将字符串构建为一个单独的步骤以提高可读性。