Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UI Scripting on Cleverbot

Hello;


I am wanting to use UI Scripting on cleverbot to be able to type something in the textbox, and also to 'copy' something from the text above (from which Cleverbot replies).

I am moderately experienced with using AppleScript, but I just need this basic idea of using UI scripting to get the right place to perform the action (action of copying typing etc.) if that makes sense.


(I hope this won't be classified as advertising but..) http://www.cleverbot.com

If someone could make a script to make it go to the textbox where it will type something in (using keystroke) and after a delay of 20 seconds, go to the reply from Cleverbot to copy.

This will be great for my understanding of UI Scripting, and I thank (and will reward) those with helpful answers.


Thank you.

iMac, Mac OS X (10.7.4)

Posted on Oct 5, 2012 3:44 AM

Reply
Question marked as Best reply

Posted on Oct 5, 2012 3:19 PM

The following script, tested under OS X 10.8.2, should do what you are asking for. Don't forget to enable access for assistive devices in the Universal Access System Preference pane.



set theQuestion to "Who is Steve Jobs?" -- some question to Cleverbot


tell application "Safari"

activate

if URL of front document is not "http://www.cleverbot.com/" then return

end tell


tell application "System Events" to tell process "Safari"

tell table 1 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of group 3 of window 1

set N1 to count rows

set value of text field 1 of group 1 of UI element 1 of row N1 to theQuestion

keystrokereturn

delay 20

set N2 to count rows

set the clipboard to (get value of static text 1 of UI element 1 of row (N2 - 1))

end tell

end tell


the clipboard-- the answer given by Cleverbot

8 replies
Question marked as Best reply

Oct 5, 2012 3:19 PM in response to TwentyEight

The following script, tested under OS X 10.8.2, should do what you are asking for. Don't forget to enable access for assistive devices in the Universal Access System Preference pane.



set theQuestion to "Who is Steve Jobs?" -- some question to Cleverbot


tell application "Safari"

activate

if URL of front document is not "http://www.cleverbot.com/" then return

end tell


tell application "System Events" to tell process "Safari"

tell table 1 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of group 3 of window 1

set N1 to count rows

set value of text field 1 of group 1 of UI element 1 of row N1 to theQuestion

keystrokereturn

delay 20

set N2 to count rows

set the clipboard to (get value of static text 1 of UI element 1 of row (N2 - 1))

end tell

end tell


the clipboard-- the answer given by Cleverbot

Oct 5, 2012 5:31 PM in response to TwentyEight

First of all, I use UIElementInspector 1.4, which can be downloaded from this Web page. Click the “Download Sample Code” button in the upper left corner of the page. You'll just need the UIElementInspector item of the UIElementInspector folder.


Then, using UIElementInspector while maintaining the cursor over the text field in the Cleverbot window, you'll see this:


User uploaded file


Then you might try this:


tell application "Safari" to activate

tell application "System Events"

tell process "Safari"

text fields of groups of cells of rows of tables of groups of web areas of scroll areas of groups of groups of groups of window 1

end tell

end tell


However, you'll soon discover that the previous code cannot be compiled until you replace both “web areas” and “cells” with the more generic expression “UI elements”, like this:


tell application "Safari" to activate

tell application "System Events"

tell process "Safari"

text fields of groups of UI elements of rows of tables of groups of UI elements of scroll areas of groups of groups of groups of window 1

end tell

end tell


--> {{}, {}, {{{{{{}, {}, {}, {}, {}, {}, {}, {}, {{{{}}, {{{text field 1 of group 1 of UI element 1 of row 2 of table 1 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of group 3 of window "Cleverbot.com - a clever bot - speak to an AI with some Actual Intelligence?" of application process "Safari" of application "System Events"}, {}, {}, {}}}}}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}}}}}}}



Et voilà !


There surely exist more sophisticated methods, but this one generally works pretty well for me.

Jul 9, 2014 10:28 AM in response to TwentyEight

Well, others responded (a long time ago) on how to get to the tab. However, on the whole "fill out a comment and wait for a response" question, here's some code that works with the site as it exists today:

-- Cleverbot-submit -- Daniel A. Shockley, http://www.danshockley.com -- Fills out a comment at cleverbot.com and then waits for a response. set myComment to "Love me some scripting." -- js code to type in myComment: set javascriptToTypeSomething to "document.getElementById('stimulus').value = '" & myComment & "';" -- js code to click the Think About It button: set javascriptToThinkAboutIt to "document.getElementById('sayit').click();" -- js code to test whether the share object exists yet (once it does, the response is complete): set jsToCheckForShareObject to "document.getElementById('snipTextIcon').innerHTML" -- js code to get the response: set javascriptToGetResponse to "document.getElementById('typArea').getElementsByTagName('span')[0].innerHTML" tell application "Safari" --activate -- uncomment this to bring Safari to the front (* un-comment this block if you won't be using an already-loaded cleverbot.com tab in Safari: open location "http://www.cleverbot.com" delay 2 *) do JavaScript javascriptToThinkAboutIt in current tab of window 1 repeat delay 1 set shareObjectExists to do JavaScript jsToCheckForShareObject in current tab of window 1 if shareObjectExists is not missing value then exit repeat end repeat set checkResponse to do JavaScript javascriptToGetResponse in current tab of window 1 return checkResponse end tell

UI Scripting on Cleverbot

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