Half way there with a AppleSript

Matsaki

Registered
I am implementing a AppleScript in my FileMaker Pro 9 to automate som tasks from FM to the web. I have the code half working:

set cell_Value to ((cellValue of cell 3) as string)

tell application "Safari"
activate
make new document
set URL of document 1 to "https://www10.pbkoutsourcing.com/clientweb_collect/searchaccount.php"
end tell

tell app "System Events" to tell process "Safari" to keystroke tab & cell_Value & return

1. I don't know where or what field name I should put the value in, in the form on the webb page? Here is the HTML code for that field where the value should go in:

<td>Kundnummer: </td>
<td><input class="text_input" type="text" name="type_2" style="width:200px" value=>input></td></tr><tr>
<td height=20>Början på namn: </td>
<td><input class="text_input" type="text" name="type_3" style="width:200px" value=>input></td><td width=40> </td>

2. To then hit "Return" don't work for some reason so I have to manually click. Is there a way around that? Here is the "Search" button HTML:

<td height=20 colspan=5 align="right" valign="bottom"><input type="button" style="width:>60" value="Sök" onclick="javascript:set_action('search','Inga sökvärden har >angetts.');">
<input type=hidden name = "action"></input>

And my last problem is that every time I hit the button in FM a new window is opening, and then I would have hundreds of new windows. I need the same window to be used all the time.

I truly hope I can get some help here or directions where to ask. I did try the Apple discussion, and this is as far as we got :(
 
Nobody working with AppleScript here?

I am coming closer but:

When the script copies the value from Filemaker cell 3 and are supposed to paste I insert it on the webbform i inserts it in the first field / tab. I want it in the second.

This pice of AS-code looks like this now:

tell app "System Events" to tell process "Safari" to keystroke tab & cell_Value & return

How can I change it to understand that it's another field? By tab or do I have to make it work with the HTML code on the webb page?
 
You should be able to use "keystroke tab" to move forms. If that's not working, you might want to split the keystroke commands, e.g.:
Code:
keystroke tab
keystroke cell_Value
keystroke return

I haven't done exactly what you're trying, but I have run into problems with AppleScript entering text commands faster than the application can properly receive them (go figure).

I think there's a better way, though: Safari has a "do JavaScript" command, and it's easy to populate and submit forms with JavaScript. I assume these input fields are contained in a form tag, right? If so, this will work:
Code:
tell application "Safari"
	do JavaScript "document.form_name.type_2.value='some text here';" in tab 1 of window 1
end tell
And then you could also do JavaScript "document.form_name.submit();" when you're done.
 
I'm truly sorry, but I don't follow your suggestion as I'm totally not a programmer. I'm just trying to learn some and make a simple AS for FM to work with Safari.

COuld I please ask you to show me what you mean, how the whole code from start to end could look like. With getting ID No. from cell 3 in FM and going to the URL etc.

Sorry again and thanks in advance.
 
I'm afraid I can't help you much with the FM part of the script, since I don't have FM and have never used it.

As for the Safari part, it looks like you almost have it done already. I think the final entire script should look something like this:

Code:
tell application "FileMaker Pro"
set cell_Value to ((cellValue of cell 3) as string)
end tell

tell application "Safari"
activate
make new document
set URL of document 1 to "https://www10.pbkoutsourcing.com/clientweb_collect/searchaccount.php"

do JavaScript "document.form_name.type_2.value='" & cell_Value & "';" in tab 1 of window 1
do JavaScript "document.form_name.submit();" in tab 1 of window 1

end tell

In the two "do JavaScript" lines, you'll need to replace "form_name" with the name of the form in the web page source. Look in the page source for something like <form name="form_name">, which should be right above the HTML snippet you already posted.
 
The information provided at Apples' Discussions' AppleScripts' 'From Filemaker to the web' thread cannot be any more clear.

You failed to provide the information requested, so further assistance may be provided. Instead, you post your problem (and a portion of a reply) to another web site.
 
And you are now the official police of forum behaviors and regulations. Congratulations!

If the answer was clear and working I would not have to continue to ask in this forum? Right?

And the solution with JavaScript given by "Mikuro" is far better then the not working method I got from Apple discussion board.

Thanks Mikuro!
 
When I run the AppleScript you gave me I get an error saying:

"Syntax Error

Expected end of line, etc. but found number

And the number it shows is The first No. 1 in the code part "tab 1 of window 1"

The HTML code for the correct cell looks like this:

Code:
<td>Kundnummer: </td>
<td><input class="text_input" type="text" name="type_2" style="width:200px" value=>input></td></tr>/CODE]
 
It could be that we're using different versions of Safari (I'm using the 3.0 beta), and the syntax of the "do JavaScript" command has changed. Open Safari's scripting dictionary (under Script Editor's File menu > Open Dictionary) and take a look.

Or you could just try removing the "in tab 1 of window 1" part. It doesn't work for me without it, but it really ought to, anyway. That's probably a bug in my Safari beta.
 
No it's not a Safari problem as Filemaker don't accept the code, and also when i test the code in AppleScript editor I get the same result / error. I tried just to copy your code as you wrote it:

tell application "FileMaker Pro"
set cell_Value to ((cellValue of cell 3) as string)
end tell

tell application "Safari"
activate
make new document
set URL of document 1 to "https://www10.pbkoutsourcing.com/clientweb_collect/searchaccount.php"

do JavaScript "document.form_name.type_2.value='" & cell_Value & "';" in tab 1 of window 1
do JavaScript "document.form_name.submit();" in tab 1 of window 1

end tell
 
Back
Top