Hello all,
we run whistleblower on our webserver, which is a great app and tells you if the server crashes and then can perform applescripts.
I want an applescript to go to a URL fill in a form and send it. The form being filled in will then text message my mobile phone and tell me!
Anyone know how i do it?
You don’t have to go to the web page! You just need the preconfigured form data sent via a URL. (i.e. all of the keys and their values.)
Check out the URL Access Scripting addition from Apple. There is a fine explanation (and script) about how to send a form post to a cgi script, in the new AppleScript Guidebook Help Viewer download. I have used this and it works very well. There are more parameters that you can add to the commands so check out the URL Access Scripting addition dictionary. You have to treat the addition as a application with your tell blocks, quitting it, etc.
This all works fine, but you may have trouble if your cgi requires ‘post method’ instead of ‘get’ for form info posting.
Thanks for the tip!
I have now written the following script. Which opens Netscape goes to the specifed URL and sends the message, then quits netscape.
Is there anyway of doing this but without opening the browser?
Many Thanks.
tell application "Finder"
activate
select file "Netscape Communicator?"
open selection
end tell
tell application "Netscape Communicator?"
make new document
activate
GetURL "http://www.breathe.com/services/textmessaging.html?number=07974374386&message=AppleScript+is+Great!&charleft=142%2F146&submit.x=10&submit.y=12" inside window 1
end tell
tell application "Netscape Communicator?"
activate
quit
end tell
The following script should do what yours did with less lines:
tell application "Netscape Communicator™"
activate
make new document
GetURL "http://www.breathe.com/services/textmessaging.html?number=07974374386&message=AppleScript+is+Great!&charleft=142%2F146&submit.x=10&submit.y=12" inside window 1
quit
end tell
This script should work without Netscape (if the action_URL is the correct, it seems to me that it would be a cgi file), but your messaging service is offline, so I could not test it, please let me know if you have:
set the action_URL to "http://www.breathe.com/services/textmessaging.html"
set the form_data to "number=07974374386&message=Better+Method&charleft=142%2F146&submit.x=10&submit.y=12"
set the query_results_file to (path to desktop folder as text) & "Query Results"
try
with timeout of 300 seconds -- try connecting for 5 minutes
tell application "URL Access Scripting"
download the action_URL to file ¬
the query_results_file form data form_data replacing yes with progress
quit
end tell
end timeout
on error
tell application "URL Access Scripting" to quit
end try
Thanks for all your help Ray. As you can tell Im very new to Applescript.
The shortversion works great, however sometimes Netscape Quits before it has time to send the URL.
The second version does not seem to work for me, everything appears OK, but no message is recieved! any ideas why? The form uses “get” as the method, is this the problem?
The following script using URL Access Scripting seems to work. I get the ‘your message has beeen sent’ output page on my desktop. (if this script works for you, you could try it without writing the desktop file, just sending the url). Let me know if it actually sends you the message, as I have no way of knowing (or testing, since I live in the U.S.)!
set the action_URL to "http://www.breathe.com/services/textmessaging.html?number=07974374386&message=Newer+Better+Method+Test&charleft=142%2F146&submit.x=10&submit.y=12"
set the query_results_file to (path to desktop folder as text) & "Query Results"
try
with timeout of 300 seconds -- try connecting for 5 minutes
tell application "URL Access Scripting"
download the action_URL to file ¬
the query_results_file replacing yes with progress
quit
end tell
end timeout
on error
tell application "URL Access Scripting" to quit
end try
Sorry to bug you, Im sure you have got much more important stuff to do than help me.
But can the whole process be background processing? as when the message is sent the Applescript is at the front and the webserver (Webstar) is sent to the back, which slows incoming connections.
I think URL Access has to be front application, though I am not sure. You can start your script by storing the name of the front application (Webstar) in a variable, then run script (bring URL acces to front), then (at end of script) restore webstar to the front. This should limit the amount of time Webstar has to background process. The method of process switching can be found in most Applescript books and several osaxen offer control over this type of thing. (Application Menu, Akua Sweets, Script Tools, etc.) Have fun. Let me know if you need more help. You can email me directly.
Fantastic!! works perfectly.
I got your messages at about 8pm on Saturday evening (I’m in the UK, but you’ve probably guessed that already.)
Thanks for all your help.
Talking to yourself: First sign of insanity! But, it was usefull. Thanks.