-- You must have UI scripting enabled for this to work.
-- Originally written by Nathan Henrie Sep 07, 2012
-- Originally posted at http://n8henrie.com/2012/09/applescript-to-automate-checking-checkboxes-in-your-web-browser/
display dialog "This script will try to simulate manually ticking off checkboxes in a web browser using \\"tab\\" and \\"spacebar\\" clicks. It seems to be working okay in the most recent stable versions of Safari and Chrome as of Sep 07, 2012. That said, you could unintentionally submit a form or otherwise screw something up, so please don\'t use it on anything important." & return & return & "Click \\"Cancel\\" below to exit the script, or \\"OK\\" to assume all risk for use of the script." with title "Disclaimer: USE AT YOUR OWN RISK"
tell application "Finder" to set RunningProcesses to name of every process
set numberBoxes to 0
set numberBoxes to text returned of (display dialog "Guess LOW! You can run this script again if it wasn\'t enough, but too much and you may accidentally click something." default answer "Enter only the number." with title "About how many evenly spaced boxes do you need to check?")
set numberTabs to text returned of (display dialog "Step 1: Open the page you\'d like to check." & return & "Step 2: Hit *tab* until you\'re at the first checkbox." & return & "Step 3: Make sure you\'re there by hitting the spacebar, which should toggle the box." & return & "Step 4: From there, count the number of tabs it takes you to hit the next checkbox." & return & return & "How many tabs did it take you to get from the first checkbox to the second?" default answer "Enter only the number." with title "How many tabs between checkboxes?")
set theProcess to (choose from list RunningProcesses with prompt "Choose the process for the browser you\'re using. (Working with \\"Safari\\" and \\"Google Chrome\\")" multiple selections allowed no OK button name "Shift + Tab back to the first checkbox and make it \\"checked\\" with the spacebar, then click here.") as string
try
tell application "System Events"
tell my application theProcess to activate
delay 1
tell process theProcess
repeat (numberBoxes - 1) times
repeat numberTabs times
keystroke tab
end repeat
keystroke space
delay 0.25
end repeat
end tell
end tell
end try