【发布时间】:2011-11-11 19:45:57
【问题描述】:
这是我的原始脚本。它将返回 Safari 的当前 url
NSAppleScript *scriptURL= [[NSAppleScript alloc] initWithSource:@"tell application \"Safari\" to return URL of front document as string"];
如果我想在要求脚本返回 URL 之前检查 Safari 浏览器是否打开,该怎么办?
这是我在 applescript 编辑器中的操作。所以这个脚本将检查 Safari 是否正在运行。这在 applescript 编辑器中有效
tell application "Safari"
if it is running then
//return url code here
end if
end tell
我现在需要的是使用' [[NSAppleScript alloc] initWithSource:' 直接从我的可可应用程序中调用脚本
我试过了,但它不起作用
NSAppleScript *scriptURL= [[NSAppleScript alloc] initWithSource:@"tell application \"Safari\" if it is running to return URL of front document as string"];
【问题讨论】:
-
你看过
NSRunningApplication吗?这将为您提供所需的信息,而无需借助 AppleScript。
标签: objective-c macos cocoa applescript applescript-objc