Skip to content

Instantly share code, notes, and snippets.

/key_macro.js
Created Jan 26, 2016

Embed
What would you like to do?
Keyboard macro for Mac OS X by Javascript / Applescript
/** Copyright 2016 Yutaka Kachi
Easy keyboard macro for Mac OS X
NYSL - 煮るなり焼くなり好きにしろライセンス
入力するテキストは、code_linesに、配列として直接書く。
| 日本語変換ON/OFF
^ 変換を確定する
*/
var code_lines = [
'/* hello world */',
'/* |konnnitiha^| world */',
'print("hello world")']
var browser = "Google Chrome"; // Set your browser "Safari"
var kotorie = false;
// activate browser
var app = Application(browser);
app.includeStandardAdditions = true;
app.activate();
delay(1);
var sys = Application("System Events");
// lines Loop
for (var j = 0, len = code_lines.length; j < len; j++) {
var code_char = code_lines[j].split("");
// Characters Loop
for (var i = 0, len2 = code_char.length; i < len2; i++) {
delay(0.2);
if (code_char[i] == " ") {
// for disable kotorie
sys.keyCode(49); // スペースキー
} else if (code_char[i] == "|") {
// ことりえ制御
if (kotorie == true) {
kotorie = false;
sys.keyCode(102); //英数キー
} else {
kotorie = true;
sys.keyCode(104); //かなキー
}
} else if (code_char[i] == "^") {
// ことりえ確定
if (kotorie == true) {
sys.keyCode(76); //Enter
} else {
sys.keystroke(code_char[i]);
}
} else {
sys.keystroke(code_char[i]);
}
}
delay(0.3);
sys.keyCode(76); // 改行キー
}
@ycatch

This comment has been minimized.

Copy link

commented Jan 26, 2016

@ycatch

This comment has been minimized.

Copy link

commented Jan 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.