• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Advice on controlling web pages (JavaScript) from Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Advice on controlling web pages (JavaScript) from Applescript


  • Subject: Advice on controlling web pages (JavaScript) from Applescript
  • From: gifford calenda <email@hidden>
  • Date: Tue, 04 Jan 2011 11:15:00 -0800

I'm a teacher/technologist at a K12 elementary school.

I'm using OSX Server 10.5, Workgroup Manager 10.5 and Apple Remote Desktop (ARD) 3.3.2

I mix Unix scripts and AppleScripts together to operate and maintain the lab of 32 eMacs in a school of ~70 eMacs all PowerPC

The school's Mac are running 10.5 I'm running 10.6.5 on my teacher's mac an Intel core 2 Duo

I have about 2-3 mins between classes to set up for the next class hence the use of  ARD, AppleScript and Unix scripts

The setup usually requires login into a web site with ( group ) user name and passwords. I have a script that does that using "System Events" and tabs

I looking for pointers (technical resources) to develop a more general solution using _javascript_ and its forms to set variables and submit in Applescript 

I'm only a beginner in  _javascript_ -- but I'm a quick study

One interesting resource is Fake - Mac OS X Web Browser Automation and Webapp Testing Made Simple.

But I want to beter understand how to use what Fake is doing a build it into my own Applescripts

Suggestions ?

OBTW  I have to delay to launch of Safari on each lab compute, starting Safari on all 32 lab computers swamps the server and bad thing happen, that is the first part of the script.



# This task has two parts which are run on the target machines:
# 1st part:  Kills Safari if it is running and delay for a calculated amount of time based on the name of the target machines
# 2nd part: enable GUI scripting (Human Interface Scripting) and login to ClickN Read web page and set it up for a specific Clas of students

# 1st part

# Assuming each machine is named with 1 set of consecutive digits in the name,
# and those digits are ordered from 1->n. This scrip takes the digits part of the name, set it to x,
# sleep for x*10 seconds

# The CP Mac Lab has 32 computers named:  CP-LAB-01 , CP-LAB-02 , CP-LAB-03 ... CP-LAB-32

killall "Safari"

x=`hostname | grep -o -e "[0-9]."`
let s=10#$x*5
sleep $s

#2nd part

osascript <<EndOfMyScript
--This script will lanuch the 'ClickN Read' member-login-web-page and login, then it will launch the lesson center ready for students to click their button

--GUIScripting_status()

enabledGUIScripting(true)

tell application "Safari"
activate
open location "http://www.clicknkids.com/Public/MemberLogin.php"
delay 3
end tell

tell application "System Events"
tell application process "Safari"
tell application "System Events"
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke "username"
delay 0.5
keystroke tab
delay 0.5
keystroke "password"
delay 0.5
keystroke return
delay 4
open location "http://www.clicknkids.com/SWF/ClickNREAD/LessonCenterSchoolCNR.php"
end tell
end tell
end tell

on GUIScripting_status()
-- check to see if assistive devices is enabled
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled." & return & return & "You can activate GUI Scripting by selecting the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 1 buttons {"Cancel"} default button 1
end tell
end if
end GUIScripting_status

on enabledGUIScripting(switch)
-- Call this handler and pass 'true' in the switch parameter to enable GUI Scripting before your script executes any GUI Scripting commands, or pass 'false' to disable GUI Scripting. You need not test the 'UI elements enabled' setting before calling this handler, because authorization is required only if 'UI elements enabled' will be changed. Returns the final setting of 'UI elements enabled', even if unchanged.
tell application "System Events"
activate -- brings System Events authentication dialog to front
set UI elements enabled to switch
return UI elements enabled
end tell
end enabledGUIScripting

EndOfMyScript

Cheers
Gifford

email@hidden
c.650.868.5725
h.650.631.1820




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Advice on controlling web pages (JavaScript) from Applescript
      • From: Steve Thompson <email@hidden>
  • Prev by Date: Re: How to do a goto with Applescript?
  • Next by Date: Re: Using a library to point to source folders
  • Previous by thread: Re: Using a library to point to source folders
  • Next by thread: Re: Advice on controlling web pages (JavaScript) from Applescript
  • Index(es):
    • Date
    • Thread