How to Open a Website with Applescript

NEW! AppleScript Maker Beta: Hey Everyone, I am working on a new AppleScript tool that is going to BLOW YOUR MIND! After reading this tutorial use this tool to easily build your AppleScripts. Click Here!

Hi There all…

To make applescript open to any web page you would like insert the following code into the top of your applescript document:

 

 

to goToWebPage(theWebPage)
 tell application "Safari"
 activate
 set URL of document 1 to theWebPage
 end tell
 end goToWebPage

 

 

When you would like to go to a website use this anywhere in your code.

 

goToWebPage("http://thewebsite.com")

 

NOTE: This will not work if it is already inside of a Safari Tell Statement.

 

Will work:

 

tell application "Safari"
 --some code...
 end tell

goToWebPage("http://thewebsite.com")

tell application "Safari"
 --some code...
 end tell

 

Will Not Work:

 

tell application "Safari"
 goToWebPage("http://thewebsite.com")
 end tell

4 Responses to “How to Open a Website with Applescript

  • Hi Samuel, Thanks a bunch for the code examples.

    Note that the code in many of your examples cannot be copy/pasted without causing runtime errors. I’m not sure the culprit, but my mac copies open and closed quotes from your web pages to the applescript editor, and the quotes cause a strange error that many newbies won’t easily recognize.

    I hope this helps,

    Michael

  • It says that “can’t continue to webpage”

    to goToWebPage(“http://www.google.com”)
    tell application “Safari”
    activate
    set URL of document 1 to theWebPage(“http://www.google.com”)
    end tell

    end goToWebPage

    goToWebPage(“http://www.google.com”)

    • Hey Raceer,
      I think you might have goToWebPage inside of a safari tell statement. You have to put it outside of the tell statement for it to work. So instead of
      Tell Application “Safari”
      goToWebPage(“http://www.google.com”)
      end tell

      it needs to be like this:

      goToWebPage(“http://www.google.com”)
      Tell Application “Safari”
      other code you want to do…
      end tell

Trackbacks & Pings

  • How to Get AppleScript to Wait for a Page to Load :

    […] previous tutorials we covered  how to make applescript open a web page, how to use AppleScript to fill out forms on a web page, and how to click buttons on web pages […]

    2 years ago

Leave a Reply

Your email address will not be published. Required fields are marked *