Use of Tab button using Applescript

Moakesy

macrumors regular
Original poster
Mar 1, 2013
245
384
UK
Hi

I'm very, very new to Applescript, and have got stuck almost immediately.

I'm a member of a sports club, and I want to automate the posting of the weekly training schedule on the club forum. I can get the script to create a new thread easily enough, but in order to enter the relevant text, I need to first select either the 'Title' field or the 'Message' field. This is where I'm getting stuck.

If I were to just type it in, I'd hit the Tab key to select the field, then enter text. But I can't get my script to do that for me.

Example code below (I've switched the URL to Macrumors forum for ease)...

Using Keystroke command
Code:
tell application "Safari" to launch
delay 0.1
open location "http://forums.macrumors.com/newthread.php?do=newthread&f=73"
keystroke tab
Gives me the following error : Can't get keystroke " ".

So I thought I'd try the Key Code command (#48 is tab I believe)

Code:
tell application "Safari" to launch
delay 0.1
open location "http://forums.macrumors.com/newthread.php?do=newthread&f=73"
key code 48
But that gives me error "Expected end of line, etc. but found identifier." at the key code statement.

I've googled this for ages, and everywhere I look, it seems I'm doing the correct thing, so why am I getting errors? I must be missing something simple?

All I want to do is select the field so I can key in 'Monday Night Swim' or something similar....it can't be that hard can it?

Thanks in advance
Steve
 

Bruno09

macrumors 68020
Aug 24, 2013
2,202
146
Far from here
Hi,

try this :

Code:
tell application "Safari" to launch
delay 0.1
open location "http://forums.macrumors.com/newthread.php?do=newthread&f=73"
delay 1
tell application "System Events" to keystroke tab
 

Moakesy

macrumors regular
Original poster
Mar 1, 2013
245
384
UK
It works...!!!

Thanks for that....really appreciated!!

Off to have a go at the next challenge now!!

Cheers