Skip to content

Instantly share code, notes, and snippets.

@devinberry
Created August 27, 2016 04:47
Show Gist options
  • Save devinberry/195ca1b9e78416877d6fcd470b2e566c to your computer and use it in GitHub Desktop.
Save devinberry/195ca1b9e78416877d6fcd470b2e566c to your computer and use it in GitHub Desktop.
Applescript keyboard emulation with web email login form
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
(*
Proof of concept to automate web based email login
Using keyboard emulation on a web form
*)
tell application "Google Chrome"
-- Uncommnet the below and enter in the web address of your email login page
#open location "http://webmail.domain.com"
delay 1
tell window 1
tell tab 1
activate
-- Uncomment this and change to the id name etc of the first form field
#execute javascript ("document.getElementById('nameuser').focus();")
tell application "System Events"
delay 1
-- Uncomment the below and fill in your email address up to the period
#set textBuffer to "email@domainname"
repeat with i from 1 to count characters of textBuffer
keystroke (character i of textBuffer)
delay 0.05
end repeat
-- this is considered special character so we use key code
delay 0.05
key code 47 -- this is the keycode for a period
delay 0.05
-- Uncomment this and add the end to the email address com,net,org etc.
#set textBuffer to "ending"
repeat with i from 1 to count characters of textBuffer
keystroke (character i of textBuffer)
delay 0.05
end repeat
keystroke tab
delay 1
(*
most passwords are going to have special chars and upper lower case use key code
replace the below with the actual key codes
best reference is https://manytricks.com/keycodes/
*)
key code 18 using {shift down} -- exclamation mark
key code 5
key code 29
key code 37
-- the next field was a login button this emulates the keyboard
keystroke tab
keystroke return
end tell
end tell
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment