Skip to content

Instantly share code, notes, and snippets.

@darfink
Last active January 24, 2020 18:35
Show Gist options
  • Save darfink/66b79e685cb18630c67e71e619b0d06c to your computer and use it in GitHub Desktop.
Save darfink/66b79e685cb18630c67e71e619b0d06c to your computer and use it in GitHub Desktop.
ItemAutocomplete demo script (AppleScript) - JXA
const getRandomNumber = (min, max) => Math.random() * (max - min) + min;
const KeyCode = function(code, shift) {
this.code = code;
this.shift = shift;
};
const ENTER = new KeyCode(36);
const TAB = new KeyCode(48);
const SHIFT_TAB = new KeyCode(48, true);
const BACKSPACE = new KeyCode(51);
const ESCAPE = new KeyCode(53);
const script = [
['Let me show you ItemAutocomplete.'],
['It can find any item;', 1, ' [Ashb', 1, TAB, 1, SHIFT_TAB, 1, ENTER],
['It is case insensitive by default;', 1, ' [savage gladiator l', 1, ENTER],
['Unless, you use 1 or more uppercase letters;', 1, ' [Savage Gladiator L', 2, BACKSPACE, 1, 'l', 2, ENTER],
['You can search with substrings;', 1, ' [healing p', 1, TAB, 0.2, TAB, 0.2, TAB, 1.5, ENTER],
['Or actually, it\'s a fuzzy search.', 1, ' Just type any part of an item name;', 1, ' [crfe', 2, ENTER],
['You can combine fuzzy search with case sensitivity to quickly find items;', 1, ' [BNM', 1.5, ENTER, 1, '[TBW', 1, ENTER, 1, '[S,', 2, ENTER, 1],
['Here are some other examples;', 1, ' [hiwi', 1, ENTER, 1, '[sksh', 1.5, ENTER, 1, '[DevL', 2, ENTER],
['[fro6', 1, ENTER, 1, '[CFL', 2, ENTER],
['Lastly, if you use an AH addon,', 1, ' you can check out AH prices whilst out travelling.'],
['[arc', 0.5, 'cr', 3],
];
const wow = new Application('/Applications/World of Warcraft/_classic_/World of Warcraft Classic.app');
const systemEvents = new Application('System Events');
// Put the WoW window in front
wow.activate();
delay(1);
// Open the chat input
systemEvents.keyCode(ENTER.code);
delay(0.15);
for (let line of script) {
for (let segment of line) {
switch (segment.constructor.name) {
case 'String':
for (let character of segment.split('')) {
systemEvents.keystroke(character);
delay(getRandomNumber(0.05, 0.15));
}
break;
case 'Number':
delay(segment);
break;
case 'KeyCode':
if (segment.shift) {
systemEvents.keyCode(segment.code, { using: 'shift down' });
} else {
systemEvents.keyCode(segment.code);
}
break;
}
}
// Remove the character inputs
delay(1);
systemEvents.keystroke('a', { using: 'control down' });
delay(0.5);
systemEvents.keyCode(BACKSPACE.code);
delay(0.5);
}
// Close the chat input
systemEvents.keyCode(ESCAPE.code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment