Newbie trying to do JavaScript in an applescript

I posted a previous question that received no replies, so this is an attempt to ask a better question. I’m a new Mac user and I’m trying to write an applescript that will start XM radio online automatically and choose a station so I could wake up to it. Thus far I can open Safari and navigate to the correct URL. My script looks like this so far (the delays are in there temporarily, I’m just trying to get the main part of the script to work):

tell application “Safari”
activate
open location “http://xmro.xmradio.com/xstream/index.jsp
delay 10
do JavaScript “/xstream/login_servlet.jsp?tabindex=1&tabindex=2” in window 1
delay 4
do JavaScript “http://xmro.xmradio.com/xstream/_js/validate.js” in window 1
delay 4
do JavaScript “http://xmro.xmradio.com/xstream/index.jsp” in window 1
end tell

The problem I’m having is I don’t know much about JavaScript, so I don’t know what syntax to use for the jsp calls. I’ve tried many variations in the do JavaScript "/xstream/login_servlet.jsp statement. (My id and password are automatically filled in when I navigate to the page).

If someone could help, I’d be very grateful.

Here’s what the source for the URL looks like:

XM Radio - XM RADIO ONLINE #leftbg { background-color:#FFCC66; background-image:url("/images/home_bg.gif"); background-repeat:no-repeat; } #not_yet_bg { background-color:#FFCC66; background-image:url("/images/not_yet_bg.gif"); background-repeat:no-repeat; }

a.tDkRed {color:#990000; text-decoration:underline; font-weight:bold;font-size:11px;}
a.tDkRed:hover {color:#990000; text-decoration:underline; font-weight:bold;font-size:11px;}

	<td><a href="http://www.xmradio.com/xstream/" onMouseOver="img_act('b_listennow')" onMouseOut="img_inact('b_listennow')"><img name="b_listennow" src="http://img.xmradio.com/images/b_listennow.gif" width="104" height="60" border="0" alt="Listen Now"></a></td>
	
</tr>
<tr valign="top" class="bBlack"><!-- row 2 -->
	<td><a href="http://www.xmradio.com/learn/index.jsp" onMouseOver="img_act('b_howitworks')" onMouseOut="img_inact('b_howitworks')"><img name="b_howitworks" src="http://img.xmradio.com/images/b_howitworks.gif" width="148" height="30" border="0" alt="Learn About XM"></a></td>
	<td><img src="http://img.xmradio.com/images/spacer.gif" width="1" height="30" border="0"></td>
	<td><a href="http://www.xmradio.com/get_xm" onMouseOver="img_act('b_getxmradio')" onMouseOut="img_inact('b_getxmradio')"><img name="b_getxmradio" src="http://img.xmradio.com/images/b_getxmradio.gif" width="148" height="30" border="0" alt="Get XM Radio"></a></td>
	<td><img src="http://img.xmradio.com/images/spacer.gif" width="1" height="30" border="0"></td>
	<td><a href="http://www.xmradio.com/programming/programming_main.jsp" onMouseOver="img_act('b_programming')" onMouseOut="img_inact('b_programming')"><img name="b_programming" src="http://img.xmradio.com/images/b_programming.gif" width="148" height="30" border="0" alt="Programming"></a></td>
	<td valign="bottom" align="right">

		<img src="/images/spacer.gif" width="104" height="1" border="0">
		
	</td>
</tr>
With XM Radio Online you'll get unlimited access to over 75 channels of amazing programming including:
  • All of XM's 100% commercial-free music channels
  • XM's exclusive music series Artist Confidential™ and Then...Again...Live!™
  • Online-exclusive channels, including XM Liquid Metal, Special X® and On the Rocks®
  • The Bob Edwards Show, from XM's Public Radio channel
  • Uncensored comedy including the outrageous, uninhibited talk duo, Opie & Anthony
See which XM Satellite Radio channels are available on the
XM Radio Online Channel Lineup.


Listener Support - Find answers to frequently asked questions, details about system requirements, user agreements and other tips for using XM Radio Online.
												<tr>
													<td></td>
													<td class="tYellow">Email:</td>
													<td class="tYellow">Password:</td>
													<td></td>
												</tr>
												<tr>
													<td><img src="/images/sign_in.gif" width="54" height="10" border="0"></td>
													<td class="tBlack"><input type="text" name="user_id" size="15" class="tBlack" tabindex="1"> </td>
													<td class="tBlack"><input type="password" name="pword" size="15" class="tBlack" tabindex="2"> </td>
													<td class="tBlack" width="100%"><input type="image" onClick="return checkForCookies()" name="go" src="/images/go.gif" align="absmiddle" tabindex="3"></td>
												</tr>
												<tr>
													<td colspan="2"></td>
													<td colspan="2"><input type="hidden" value="default" name="userForward"><a href="/xstream/registration/reg_reminder.jsp" class="tYellow">Forgot your password?</a></td>
												</tr>
												<tr>
													<td colspan="4"><img src="/images/spacer.gif" width="1" height="15" border="0"></td>
												</tr>
											</table>
										</td>
									</tr>
									<tr bgcolor="#FF9933">
										<td><a href="/xstream/subscriber.jsp"><img src="/images/already_sub.gif" width="318" height="33" border="0"></a></td>
									</tr>
									<tr bgcolor="#FF9933">
										<td class="tLgBlack">
											<table cellspacing="10" cellpadding="0" border="0" width="100%">
												<tr>
													<td valign="top"><a href="/xstream/subscriber.jsp"><img src="/images/already_arrow.gif" width="21" height="20" border="0"></a></td>
													<td class="tLgBlack" width="100%"><a href="/xstream/subscriber.jsp" class="tLgBlack">You may be eligible for <b>XM Radio Online,</b> at no additional charge.</a>
													<div align="right"><a href="/xstream/subscriber.jsp"><img src="/images/create_account.gif" width="114" height="11" border="0"></a></div></td>
													<td><img src="/images/spacer.gif" width="13" height="1" border="0"></td>
												</tr>
											</table>
										</td>
									</tr>
									<tr bgcolor="FFCC66">
										<td><img src="/images/not_yet_divide.gif" width="318" height="3" border="0"></td>
									</tr>
									<tr id="not_yet_bg" bgcolor="FFCC66">
										<td class="tLgBlack">
											<table cellspacing="15" cellpadding="0" border="0" width="100%">
												<tr>
													<td class="tLgBlack" width="100%"><img src="/images/not_yet.gif" width="283" height="19" border="0">
													<br>XM Radio Online is a great way to experience the innovative programming you can hear on the XM service.
													<div align="right"><table cellpadding="0" cellspacing="0" border="0">
															<tr>
																<td><a href="/xstream/registration/registration.jsp?userForward=default"><img src="/images/3_day_trial.gif" width="281" height="100" border="0"></a></td>
															</tr>
															<tr>
																<td><a href="/xstream/registration/dell_marketing.jsp"><img src="/images/dell_trial.gif" width="281" height="95" border="0"></a></td>
															</tr>
															<tr>
																<td><a href="/xstream/subscription_overview.jsp?userForward=subscription"><img src="/images/subscribe_to_xmro.gif" width="283" height="80" border="0"></a></td>
															</tr>
														</table></div>
													</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
							<td bgcolor="#B29E84"><img src="/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
						</tr>
						<tr>
							<td colspan="2"><img src="/images/home_left_bottom.gif" width="417" height="9" alt="" border="0"></td>
							<td><img src="/images/spacer.gif" width="4" height="1" alt="" border="0"></td>
							<td colspan="2"><img src="/images/home_rt_bottom.gif" width="319" height="9" alt="" border="0"></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</td>
</tr>
© Copyright 2001-05 XM Satellite Radio. All Rights Reserved. Privacy Policy | Terms & Conditions

Model: iMac G5
AppleScript: 1.10
Browser: Safari 412.2
Operating System: Mac OS X (10.4)

“do javascript” executes actual javascript code; you can’t pass it a URL.

For example:

tell application "Safari"
	do JavaScript "alert(\"hello\");" in document 1
	set myCode to "alert(\"world\")"
	do JavaScript myCode in document 1
end tell

I’m not sure what you want to do exactly because I don’t have an XM Radio account, but try this:

tell application "Safari"
	do JavaScript "document.forms[0].submit()" in document 1
end tell

That should log you in if the user/pass are filled in.

Thanks, PCheese. That worked beautifully. Once I implemeted your code, I was able to finish the script and launch the player successfully. I really appreciate your help.

Steve