-
-
Save cephurs/1d3dcdfaf96cba81a659007ab8b9b5ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ██████╗ █████╗ ██████╗ ██╗ ██╗███████╗██╗ ██╗██████╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ | |
// ██╔══██╗██╔══██╗██╔══██╗██║ ██╔╝██╔════╝╚██╗ ██╔╝██╔══██╗██╔═══██╗██╔══██╗██╔══██╗██╔══██╗██║ | |
// ██████╔╝███████║██║ ██║█████╔╝ █████╗ ╚████╔╝ ██████╔╝██║ ██║███████║██████╔╝██║ ██║██║ | |
// ██╔══██╗██╔══██║██║ ██║██╔═██╗ ██╔══╝ ╚██╔╝ ██╔══██╗██║ ██║██╔══██║██╔══██╗██║ ██║╚═╝ | |
// ██████╔╝██║ ██║██████╔╝██║ ██╗███████╗ ██║ ██████╔╝╚██████╔╝██║ ██║██║ ██║██████╔╝██╗ | |
// ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ | |
// No Donut! | |
// Built from code by : https://gist.github.com/jiaaro and a twitter post from: https://twitter.com/zackwhittaker/status/1084554101625626624 | |
// Not for malicious use. You assume all responsibility for anything you do with this. Don't be a jerk. If I find out you used this to hurt people. | |
// Just remember TAKEN. Get what I'm sayin? | |
// How to test: | |
// 1. copy gist to text file and save as badkeyboard.js (or whatever you want to name it) | |
// 2. Open terminal or iterm and go to the directory where you saved the file. | |
// 2. Run the following command "osascript -l JavaScript badkeyboard.js" | |
// 3. If you get a prompt just click "Ok" - There are ways around this too but we are testing! | |
// | |
// How to run it with Applescript: | |
// 1. Open "Script Editor" (requires OS X 10.10 Yosemite or greater) | |
// 2. Change the language from "AppleScript" to "JavaScript" | |
// 3. Paste the code below. | |
// | |
// More info: | |
// https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html | |
var sys_events = Application("System Events"); | |
// More keycodes can be added. Keycode reference: | |
// http://www.codemacs.com/coding/applescript/applescript-key-codes-reference.8288271.htm | |
var key_codes = { | |
"→": 124, | |
"←": 123, | |
"↑": 126, | |
"↓": 125, | |
"⏎": 36 | |
}; | |
var modifiers = { | |
"⌘": "command down", | |
"^": "control down", | |
"⌥": "option down", | |
"⇧": "shift down" | |
}; | |
function press(hotkey) { | |
var using = []; | |
while (hotkey.length > 1) { | |
if (modifiers[hotkey[0]] == undefined) { | |
throw new Error(hotkey[0] + " is not a recognized modifier key"); | |
} | |
using.push(modifiers[hotkey[0]]); | |
hotkey = hotkey.slice(1); | |
} | |
if (key_codes[hotkey] != undefined) { | |
sys_events.keyCode(key_codes[hotkey], {using: using}); | |
} | |
else { | |
sys_events.keystroke(hotkey.toLowerCase(), {using: using}); | |
} | |
} | |
function type(text) { | |
for (var i=0; i < text.length; i++) { | |
sys_events.keystroke(text[i]); | |
} | |
} | |
function menu_item() { | |
if (!arguments.length) return; | |
var process = sys_events.processes.whose({"frontmost": true})[0]; | |
var menu_bar = process.menuBars[0].menuBarItems[arguments[0]]; | |
var menu_item = menu_bar; | |
for (var i=1; i < arguments.length; i++) { | |
menu_item = menu_item.menus[0].menuItems[arguments[i]]; | |
} | |
menu_item.click(); | |
} | |
//////////////////////////////////////////////////////////// | |
// Example use: Chrome | |
//////////////////////////////////////////////////////////// | |
var Chrome = Application("Google Chrome"); | |
// Give Chrome the focus | |
Chrome.activate(); | |
// Give it a second, it's practically magic (literally waits 1 second) | |
delay(1.0) | |
// New window: | |
press("⌘N") | |
// Another new Window | |
menu_item("File", "New Window") | |
// select address bar | |
press("⌘L") | |
// enter a url | |
type("https://revoked.badssl.com") | |
// press enter and wait for the page to load before doing more stuff | |
press("⏎") | |
delay(.5) | |
// open your favorite bad keyboard site in a new tab | |
//press("⌘T") | |
delay(.5) // wait for new tab animation so we can start typing | |
type("thisisunsafe") | |
press("⏎") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment