Clearing the clipboard and activating the return command

Hello,

I’ve been browsing the forums all yesterday in search of an applescript to fill-in and complete a username/password scheme inside a network application named TestTaker (proficiency testing for elementary students). I’ve got as far as mounting the server, entering the first username field and tabbing to the password login but that’s it. This is what I have thus far:

tell application “Finder”
say “launching MAPS testing…please wait”
mount volume “afp://username:password@serveripaddress:548/Share Volume”
set thepath to open “Macintosh HD:Users:student:applications:TestTaker.app”
tell application “TestTaker” to activate
tell application “System Events”
set the clipboard to “username”
keystroke “v” using command down
keystroke tab as string
end tell
end tell

My problem resides in clearing the clipboard, setting the password and pasting that to the password field, all while pressing return thereafter to complete the login screen within that application and making things ultimately easier for our students (and more appropriately a technically challenged staff).

Please let me know if anyone has any ideas. I feel like I’m so close to completing this automation. :smiley:

Thank you,
Anthony

Model: eMac/iBook G3’s/G4’s (with both Panther and Tiger)
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.3.9)

You don’t need to clear the clipboard, just go ahead and set it to the next value you want to use:

tell application "Finder"
    say "launching MAPS testing...please wait"
    mount volume "afp://username:password@serveripaddress:548/Share Volume"
    set thepath to open "Macintosh HD:Users:student:applications:TestTaker.app"
    tell application "TestTaker" to activate
    tell application "System Events"
        set the clipboard to "username"
        keystroke "v" using command down
        keystroke tab as string
		set the clipboard to "Mahonri"
		--Do whatever you want with the new value....
    end tell
end tell

If you then want to clear the clipboard, just set it to and empty string:

set the clipboard to ""

Good Luck,

Thank you Craig for the timely information.

Unfortunately that’s exactly what my initial instincts told me too. I repeat the set to command but instead the AppleScript (or the TestTaker application) disregards the username information and places the same “password” in both the Username and Password fields (why I have no clue).

I also used your suggestion of clearing the clipboard by writing:

set the clipboard to “”

yet that still yields the same results (except it enters the password twice in the password field while placing yet again the password in the Username field).

Does this sound like it makes any sense? I’m starting to believe there should be another option besides using the clipboard within AppleScript to make this work.

Plus I still need to engage the return key on the keyboard to forward the students in TestTaker.

Thank you for your help though,
Anthony

It doesn’t seem necessary to use the clipboard if you are using “System Events” already.

tell application "Finder"
say "launching MAPS testing...please wait"
mount volume "afp://username:password@serveripaddress:548/Share Volume"
set thepath to open "Macintosh HD:Users:student:applications:TestTaker.app"
tell application "TestTaker" to activate
delay 1  --use delays with System Events, the script can get ahead of the computer
   tell application "System Events"
      keystroke ("username" & tab & "password")
      key code 76  --this is the Enter key. If you need the Return key, change this line to "keystroke Return"
   end tell
end tell

Matt-Boy…you rock!

Thank you! How did you know that information? Is there a guide outlining key codes and when to use delays?

Suffice to say it works perfectly now. Thank you again.

Anthony:)

I use a little utility called “Full Key Codes” which you can find at versiontracker.com. You hit a key and it gives you the code (use the “dec” code in the bottom right corner).

As far as delays that just comes from my experience using System Events. It can easily get ahead of the computer and basically hit the keys you indicated before the computer is ready to accept it so it looks like the script never send the keystrokes. Anytime it seems like it is missing a step, try putting a long delay in to see if it fixes it. Then see how short you can make the delay and have it still work. You can indicate a Delay 0.5 if you want less than a second, incidentally.