image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
LinkBack Thread Tools
  #1  
Old August 11th, 2003, 12:48 AM
Registered User
 
Join Date: Jun 2003
Location: oregon
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
blackoutspy is on a distinguished road
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=\
Reply With Quote
  #2  
Old August 11th, 2003, 02:50 AM
Arden's Avatar
Where mah "any" keys at?
 
Join Date: Dec 2002
Location: San Francisco
Posts: 7,751
Thanks: 0
Thanked 0 Times in 0 Posts
Arden is on a distinguished road
Use the Record option.
__________________
System:
2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 200 GB hard drive, runs 10.5.6
1.6 GHz iMac G5, 1.5 GB RAM, 250 GB hard drive, runs 10.4.11 (slightly out of commission at this time)
iPhone, 4 GB, OS X 2.2.1
Reply With Quote
  #3  
Old August 11th, 2003, 02:57 AM
Registered User
 
Join Date: Jun 2003
Location: oregon
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
blackoutspy is on a distinguished road
safari doesn't support record=\ and neither does IE
Reply With Quote
  #4  
Old August 11th, 2003, 03:13 AM
Arden's Avatar
Where mah "any" keys at?
 
Join Date: Dec 2002
Location: San Francisco
Posts: 7,751
Thanks: 0
Thanked 0 Times in 0 Posts
Arden is on a distinguished road
Oh. Then drag the little icon next to the URL to the Desktop, and tell Applescript to launch this URL file.
__________________
System:
2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 200 GB hard drive, runs 10.5.6
1.6 GHz iMac G5, 1.5 GB RAM, 250 GB hard drive, runs 10.4.11 (slightly out of commission at this time)
iPhone, 4 GB, OS X 2.2.1
Reply With Quote
  #5  
Old August 11th, 2003, 05:05 AM
Registered User
 
Join Date: Jun 2003
Location: oregon
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
blackoutspy is on a distinguished road
what would be the code for that?
Reply With Quote
  #6  
Old August 11th, 2003, 11:29 PM
Arden's Avatar
Where mah "any" keys at?
 
Join Date: Dec 2002
Location: San Francisco
Posts: 7,751
Thanks: 0
Thanked 0 Times in 0 Posts
Arden is on a distinguished road
Um...
Code:
tell application "Finder"
  open file "XYZ"
end tell
I should think...

Just record your actions as you open the URL file.
__________________
System:
2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 200 GB hard drive, runs 10.5.6
1.6 GHz iMac G5, 1.5 GB RAM, 250 GB hard drive, runs 10.4.11 (slightly out of commission at this time)
iPhone, 4 GB, OS X 2.2.1
Reply With Quote
  #7  
Old August 11th, 2003, 11:58 PM
dlloyd's Avatar
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
dlloyd is on a distinguished road
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
Reply With Quote
  #8  
Old August 12th, 2003, 07:19 AM
Registered User
 
Join Date: Jan 2002
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
bluehz is on a distinguished road
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
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.