Inputting Text in Safari

I'm trying to create a script that will automate the sending of text messages via an html webpage.

For instance, is there a way I could get Applescript to insert a pre-written portion of text into this very reply box?

I have a list of several hundred persons, each with an associated webpage with a text input box in safari that allows me to send a message, and I have created a script that will open up a url for each one, but I do not know how to get Applescript to paste a message into the box.

Any idea how to do this?

Posted on Sep 12, 2005 12:48 PM

Reply
10 replies

Sep 12, 2005 2:15 PM in response to Jeffrey Kiok

The problem is, how do you think you will address a given text box?

The answer is, you have to use the Document Object Model attached to the html file. If the file is correctly structured you can use the DOM, and javascript is the natural way of interfacing html's DOM.

Google Apple's site for DOM 2, Safari, and javascript. javascript is not too hard, furthermore you need very basic features.

Sep 13, 2005 3:00 PM in response to Jeffrey Kiok

Two ways of doing this.

This one you have to click in the textbox you want then run this script assuming your using Safari.
tell application "Safari"
activate
tell application "System Events"
keystroke "This is where you type the text you want inserted"
end tell
end tell

The second takes a little setup.
open the page you wanting to fill
in the view menu go to view source

then you have to find the form name, it should be something like Form name = thisform

then you need the name of the field you wanting to insert into, it should look something like this
<input name="textfield" type="text" class="form150" size="18" maxlength="256" value="">

then you can right the script using the actual form and field names

set theScript to "document.thisform.textfield.value='the text you want inserted'"
tell application "Safari"
activate
do JavaScript theScript in document 1
end tell

Sep 17, 2005 5:01 AM in response to Jeffrey Kiok

I posted a test page at

http://macbidder.com/textField.html

in the View menu select View Source
notice in the html code that:
the form name is form1
the field name is textfield

close the source window and run this script on my test page

set theScript to "document.form1.textfield.value='I want to insert this Text'"
tell application "Safari"
activate
do JavaScript theScript in document 1
end tell

it will put "I want to insert this Text" in the field

form1 and textfield are names I made. you will have to view the source and change to the correct names in the page your working with. also the page you want filled must be in front when you run this script

Sep 19, 2005 1:48 PM in response to Marshall Bohlmeyer

The webpage i am looking at does not follow such a format.

It has things such as:

[Add The Grendels to your Dossier]

<" action="http://www.nationstates.net/cgi-bin/index.cgi/">
<input type="hidden" name="page" value="send_message">
<input type="hidden" name="recipient" value="the_grendels">
<input type="hidden" name="chk" value="JG9Ip7XFNKdw2">

Want to wire a telegram to The Grendels?
<pre>To: The Grendels From: Blackbird</pre>
<textarea name="message" rows="8" cols="60" wrap="soft"></textarea>
<input type="submit" value="Send!">
</form>
It has every field you name except for the form name. It has a </form> tag, but I cannot find any such tag opening and naming the form.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Inputting Text in Safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.