0

我有一个 LaunchAgent,它在用户登录时调用一个应用程序。该应用程序加载一个网站。

启动代理

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>LaunchAgent.Test</string>
    <key>RunAtLoad</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
    <string>/Applications/MyApp.app/Contents/MacOS/applet</string>
    </array>
</dict>
</plist>

应用

display alert set_cookies_for_URL("http://www.apple.com")
(* AppleScript's handlers all seem to become unusable after importing frameworks.
 * To compensate, I'm relegating AppleScript/ObjC calls to the end of the file
 *)
use framework "WebKit"

on set_cookies_for_URL(URL)

    set web_view to current application's WebView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 500, 500)) frameName:"tempFrame" groupName:"tempGroup"
    set web_view's mainFrameURL to URL
    #delay to avoid release
    repeat while ((web_view's isLoading) as boolean) is true
        delay 1
    end repeat
    return "done"
end set_cookies_for_URL

我将如何将网站参数从 LaunchAgent 传递到应用程序?

4

1 回答 1

0

你可以使用这个。第二个参数(在可执行文件之后)应该是“-”,然后第三个应该是“ http://www.apple.com ”或者任何你想要的:

use framework "WebKit"
use scripting additions

set argv to (current application's NSProcessInfo's processInfo()'s arguments as list)
if (count of argv) is 3 then
    set_cookies_for_URL(item 3 of argv)
end if

quit

on set_cookies_for_URL(URL)
    set web_view to current application's WebView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 500, 500)) frameName:"tempFrame" groupName:"tempGroup"
    set web_view's mainFrameURL to URL
    #delay to avoid release
    repeat while ((web_view's isLoading) as boolean) is true
        delay 1
    end repeat
end set_cookies_for_URL

编辑:哦,是的,我知道为什么 AppleScript 不能识别“显示警报”。导入框架时,您必须声明“使用脚本添加”以启用完整的 AppleScript。

于 2015-08-06T21:06:47.560 回答