simple login script script error?

Hey Guys,

I wrote a simple script that should open safari, take me to a website, and keystroke my name a password. It is case sensitive, so I wrote the following script. But I keep getting this error message:

syntax error:

Expected end of line but found identifier.

Any Ideas why?


For Reference:
Login Name:
login\MYname
Password: 1234fake

[code]set theURL to “http://www.mywebsite.com

tell application “Safari” to make new document with properties {URL:theURL}
delay 5
tell application “System Events”
keystroke "login"
keystroke “my” using shift down
keystroke “name”
keystroke tab
keystroke “1234fake”
keystroke return
end tell[/code]

Hi,

a backslash is a special character to escape other special characters.
A backslash itself must be escaped with a second backslash


.
keystroke "login\\"
.

but why not directly
.

keystroke "login\\MYname"
.

?

Thanks Stefan. This gets rid of my syntax error. After it opens my web page, it doesn’t keep the front window, or main web page, selected when it goes to keystroke the info into the log in areas. It just returns the text in my script editor.

For almost all GUI scripts you have to activate the target application

tell application "Safari"
	activate
	make new document with properties {URL:theURL}
end tell
delay 5
.

So wise…so wise. One more question, but this might be a little more complex. At least for me. Obviously it isn’t the best to create a script that anyone can access any site you need a login to access. Is there a way that I can have the script access a basic text document that the script prompts me for, before it runs the script as a reference? For example:

(I know this coding doesn’t make any physical sense. I’m just trying to give you an idea of what I’m looking for it to do)

MyInfo.txt (Basic Text File Separate from Script):

login[i]-->Line 1[/i]
my–>Line 2
name–>Line 3
1234fake–>Line 4

[b]Ask where "Myinfo.txt" is:[/b]

set myLogin to file "Path of file->Myinfo.txt"
set theURL to "http://www.mywebsite.com"

tell application "Safari" to make new document with properties {URL:theURL}
activate
end tell
delay 5
tell application "System Events"
keystroke "[b]line 1[/b]" of myLogin
keystroke "[b]line 2[/b]" of myLogin  using shift down
keystroke "[b]line 3[/b]" of myLogin
keystroke tab
keystroke "[b]line 4[/b]" of myLogin
keystroke return
end tell

something like this


set myLogin to choose file with prompt "Choose Myinfo.txt"
set theURL to "http://www.mywebsite.com"
set {_user, _pass} to paragraphs 1 thru 2 of (read myLogin)
tell application "Safari"
	make new document with properties {URL:theURL}
	activate
end tell
delay 5
tell application "System Events"
	tell process "Safari"
		keystroke _user
		keystroke tab
		keystroke _pass
		keystroke return
	end tell
end tell

Amazing thank you.

I have run into one more issue. However, I don’t know if this can be taken care of in applescript, or if I have to find an answer in a javascript forum. A language I know even less about. There is one link I have to click on that I can’t tab over to using a keystroke command. What would be the best way of accomplishing this? I would just copy and paste the URL for the next page as a command for safari to go to, but the URL for the next page, and the page I am current stuck are exactly the same when I look at them in my browser window.

This depends on the link respectively the source code of the site
Safari (with AppleScript) can also perform javascript commands.

I can view the source code of the site through firefox. But when I went through it, I couldn’t find anything in the code that had the name of the link. In my case, the name of the link is (Go to Calender). Then again, I don’t know what to look for, or if that’s what I should be looking for. I was trying to find some part of the source code that had the name of the link to see if I could see the URL it was pointing the link to. Do you have any idea what I should be looking for in the coding that would tell me what part of the coding is specifically written to create that link?

Sorry, this is a lot of trial and error.
Use this script to retrieve the forms and elements


tell application "Safari"
	set maxForm to do JavaScript "document.forms.length" in document 1
	repeat with formIndex from 0 to maxForm as integer
		try
			set maxElements to do JavaScript ("document.forms[" & formIndex as string) & "].elements.length" in document 1
			repeat with elementIndex from 0 to maxElements
				try
					set theName to do JavaScript "document.forms[" & formIndex & "].elements[" & elementIndex & "].name" in document 1
					display dialog theName & " - FormIndex: " & formIndex & " / ElementIndex: " & elementIndex
				end try
			end repeat
		end try
	end repeat
end tell

and the JavaScript documentation

I ran the script and I got a bunch of different information coming up. For example:

Example 1:

htmlbevt-par 1-FormIndex 5/Element Index 5

Example 2:

htmlbevt-cnt-FormIndex 5/Element Index 6

I’m just confused as to how I can apply this?