這是我的原始腳本。它會返回Safari的當前網址如何使用[[NSAppleScript alloc] initWithSource來檢查應用程序是否正在運行:
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頁頭] initWithSource:」
我已經試過,但它不工作
NSAppleScript *scriptURL= [[NSAppleScript alloc] initWithSource:@"tell application \"Safari\" if it is running to return URL of front document as string"];
你有看'NSRunningApplication'?這將給你所需的信息,而不訴諸於AppleScript。 –