Controlling Safari from FileMaker
Jun 01, 2012 12:10 PM
This week we needed to gather data from a website and store the result into a FileMaker database running on Mac.
Everything worked great when we manually tested it in Safari, so when we tried it in using the FileMaker Web Viewer we were surprised that the page would not load as it did in Safari. We also considered the script step 'Insert from URL', but that wouldn't work since navigation of the site is required.
So we thought if it worked in Safari by hand, why not just go in that direction. So we did a few Google searches and found the AppleScript commands that we needed to make it work and came up with the following AppleScript that left :
Perform AppleScript as Calculated:"¶
property theURL : \"\"¶
¶
tell application \"Safari\"¶
¶
activate¶
¶
set theURL to URL of current tab of window 1¶
set theURL to theURL & \"&title=" & $title & "\"¶
set URL of document 1 to theURL¶
¶
delay 5¶
¶
tell application \"System Events\"¶
keystroke \"u\" using {command down, option down}¶
delay 1¶
keystroke \"a\" using command down¶
delay 1¶
keystroke \"c\" using command down¶
delay 1¶
keystroke \"w\" using command down¶
delay 1¶
keystroke \"[\" using command down¶
delay 1¶
end tell¶
¶
end tell¶
"
This code does the following:
Then in our FileMaker script, we simply Paste the Source Code Text into our field.
Let us know what you think and if you have any ideas for this...
Perform AppleScript as Calculated:"¶
property theURL : \"\"¶
¶
tell application \"Safari\"¶
¶
activate¶
¶
set theURL to URL of current tab of window 1¶
set theURL to theURL & \"&title=" & $title & "\"¶
set URL of document 1 to theURL¶
¶
delay 5¶
¶
tell application \"System Events\"¶
keystroke \"u\" using {command down, option down}¶
delay 1¶
keystroke \"a\" using command down¶
delay 1¶
keystroke \"c\" using command down¶
delay 1¶
keystroke \"w\" using command down¶
delay 1¶
keystroke \"[\" using command down¶
delay 1¶
end tell¶
¶
end tell¶
"
This code does the following:
- Define a property variable call theURL.
- Tell Safari to come to the front.
- For our needs, we grab the current Window Tab URL.
- We append a parameter "&title=123" to go to the URL.
- We pause 5 seconds to give the page time to load.
- Then we use the keyboard to navigate Safari with one second pauses between each step.
- Show the Source Code of the Page.
- Select all of the Source Code Text.
- Copy the Text.
- Close the Source Code Window.
- Then finally go back to the previous page.
Then in our FileMaker script, we simply Paste the Source Code Text into our field.
Let us know what you think and if you have any ideas for this...