Infinite Possibilities
Infinite Possibilities

Reputation: 7476

Applescript to open safari with osescript and specific URL

I am trying to run the following script:

on run proUrl
    tell application "Safari"
        make new document with properties {URL:proUrl}
    end tell
end run

This is how I try to run it: osascript script.scpt http://google.com.
I receive the following error:
script.scpt: execution error: Safari got an error: AppleEvent handler failed. (-10000)
In case I substitue the proUrl variable to "http://google.com" then it works.

How can I fix this?

Upvotes: 0

Views: 320

Answers (2)

foo
foo

Reputation: 3259

To open a URL in your default browser from the command line, just use open:

open http://google.com

See man open for more.

Upvotes: 0

regulus6633
regulus6633

Reputation: 19040

proUrl is a list of items, even if there's only 1 item you are sending to the applescript. So the actual url is "item 1 of proURL". Here's how I would write your script...

on run proUrlList
    open location (item 1 of proUrlList)
end run

Upvotes: 1

Related Questions