Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Page 1 of 2 12 LastLast
Results 1 to 8 of 11
  1. #1
    blackoutspy is offline Registered User
    Join Date
    Jun 2003
    Location
    oregon
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using applescript to open web browser and go to a site

    I've been messing around with AppleScripts and i thought it would be nice to make a script that would open a window and go to a spacific site for me, but i can't figure it out. So far all i have is:
    tell application "Safari"
    activate
    make new window
    end tell

    This is extreamly poor, i understand, but i can't find the command for new window for the life of me, much less a "goto URL" command=\

  2. #2
    Arden's Avatar
    Arden is offline Where mah "any" keys at?
    Join Date
    Dec 2002
    Location
    Spokane, WA
    Posts
    7,752
    Thanks
    0
    Thanked 1 Time in 1 Post
    Use the Record option.
    Systems:
    2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 320 GB hard drive, runs 10.6.8
    1.6 GHz iMac G5, 1.5 GB RAM, 120 GB hard drive, runs 10.4.11 (out of commission)
    iPhone 4, 16 GB, iOS 4.3.5

  3. #3
    blackoutspy is offline Registered User
    Join Date
    Jun 2003
    Location
    oregon
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    safari doesn't support record=\ and neither does IE

  4. #4
    Arden's Avatar
    Arden is offline Where mah "any" keys at?
    Join Date
    Dec 2002
    Location
    Spokane, WA
    Posts
    7,752
    Thanks
    0
    Thanked 1 Time in 1 Post
    Oh. Then drag the little icon next to the URL to the Desktop, and tell Applescript to launch this URL file.
    Systems:
    2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 320 GB hard drive, runs 10.6.8
    1.6 GHz iMac G5, 1.5 GB RAM, 120 GB hard drive, runs 10.4.11 (out of commission)
    iPhone 4, 16 GB, iOS 4.3.5

  5. #5
    blackoutspy is offline Registered User
    Join Date
    Jun 2003
    Location
    oregon
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what would be the code for that?

  6. #6
    Arden's Avatar
    Arden is offline Where mah "any" keys at?
    Join Date
    Dec 2002
    Location
    Spokane, WA
    Posts
    7,752
    Thanks
    0
    Thanked 1 Time in 1 Post
    Um...
    Code:
    tell application "Finder"
      open file "XYZ"
    end tell
    I should think...

    Just record your actions as you open the URL file.
    Systems:
    2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 320 GB hard drive, runs 10.6.8
    1.6 GHz iMac G5, 1.5 GB RAM, 120 GB hard drive, runs 10.4.11 (out of commission)
    iPhone 4, 16 GB, iOS 4.3.5

  7. #7
    dlloyd's Avatar
    dlloyd is offline Official Pianist
    Join Date
    Dec 2002
    Location
    At a keyboard. One or the other.
    Posts
    2,978
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    tell application "Safari"
    	activate
    	do JavaScript "window.open('http://www.yahoo.com')" in document 1
    end tell
    This will do what you want.

    Make sure you retain the http:// and the trailing slash though, otherwise you will get an error page.
    < Also Known As aeromusek in places >

    < PowerBook | 1.67GHz | 1024MB RAM | 120GB | 17" High Res >
    < iPod | 20GB | 3rd gen >


    "the show must go on" - the artists of the world

  8. #8
    bluehz is offline Registered User
    Join Date
    Jan 2002
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a little script I use that runs automatically every morning before I wake up. Then when I get my mornig coffee I can just sit down and all my news pages, etc are already open. While not strictly an AppleScript, it might help you out. This is a shell script that is launched by cron at a specified time.

    1. Create the text file (aake sure its TEXT not RTF) and enter the following:

    #!/bin/sh

    #
    # functions
    #
    # opennew is a function to create a new Safari window
    opennew () {
    osascript <<EOF
    tell application "Safari"
    activate
    make new document at beginning of documents
    end tell
    EOF
    sleep 5
    }

    # open a new Safari window then loads the urls listed below into that new
    window.
    # note the last url in the list does NOT have a trailing fwd slash
    opennew
    open "http://url1" \
    "http://url2" \
    "http://url3" \
    "http://url4"

    # open another window, load more urls
    opennew
    open "http://url5" \
    "http://url6" \
    "http://url7" \
    "http://url8"

    2. Save the file and change permissions to executable (chmod 755 filename).

    3. Setup a cron task to launch the file at a specific time, or you can run it manually

 

 
Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •