Skip to content

Instantly share code, notes, and snippets.

@shokai
Created March 17, 2016 19:58
Show Gist options
  • Select an option

  • Save shokai/efe5556bd9e00faf14dc to your computer and use it in GitHub Desktop.

Select an option

Save shokai/efe5556bd9e00faf14dc to your computer and use it in GitHub Desktop.
#!/usr/bin/osascript -l JavaScript
function input(emoji){
var app = Application("System Events");
app.includeStandardAdditions = true;
var currentClipboard = app.theClipboard();
app.setTheClipboardTo(emoji);
app.keystroke("v", {using: "command down"});
delay(1);
app.setTheClipboardTo(currentClipboard);
}
function getRandomEmoji(){
const emojis = [
"😀",
"😁",
"😂",
"👿",
"👺"
];
return emojis[Math.floor(Math.random()*emojis.length)];
}
input(getRandomEmoji());
@shokai
Copy link
Author

shokai commented Mar 17, 2016

AppleScript (JXA)で絵文字を入力する

  • keystrokeでは半角文字しか書き込めないので、クリップボードに入れてからcmd+vでペーストする
  • 元々クリップボードに入っていたデータは一旦退避させておいて、後でクリップボードに戻す
    • delay(1) が無いとペーストする前に戻してしまう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment