Applescript Login Item for All Users

时间:2015-07-28 15:39:56

标签: macos applescript

Using Applescript how can I register a login item for all users?

I understand that there is a library/preferences/loginwindow.plist file which holds this information.

I need to launch safari on log in and navigate to a URL. This needs to be done for any user that logs in. I've been looking to Launch Agents and this seems like my best bet.

I have the following in Library/LaunchAgents/ which is launching safari at log in but I don't know how to specifiy the URL

<?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>heymega.safari.launcher</string>
    <key>OnDemand</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/Safari.app/Contents/MacOS/Safari</string>
    </array>
</dict>
</plist>

1 个答案:

答案 0 :(得分:0)

您应该能够将url作为参数包含在内:

<string>/Applications/Safari.app/Contents/MacOS/Safari</string>
<string>http://example.com</string>

如果这不起作用,您可以尝试致电osascriptSafari定向到网址:

/Applications/Safari.app/Contents/MacOS/Safari & sleep 1 && osascript -e 'tell application "Safari" to open location "http://www.example.com"'

osascript方法使用sleep,以便Safari在执行之前有机会启动。