我試圖設置一個簡單的Apple JXA腳本來將着名的聳肩表情符號寫入屏幕(它模擬按鍵我猜)。我嘗試的每件事情都會產生這個「¯\ _(a)_ /¯」。我假設,因爲我正在使用按鍵來模擬按鍵,並且我沒有日文鍵盤,所以我一直都會這樣做。也許我應該將字符串複製到剪貼板?JXA keystroke無法使用特殊字符
這裏是我到目前爲止的代碼:
// Shrug Script
// ¯\_(ツ)_/¯
//
// contains special character:
// ツ
// KATAKANA LETTER TU
// Unicode: U+30C4, UTF-8: E3 83 84
// thought maybe I needed to decode it ¯\_(ツ)_/¯
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
// this is the newer "Script" aka Javascript way
var sysEvents = Application('System Events');
// this didn't work:
// sysEvents.keystroke("¯\\_(ツ)_/¯");
// this doesn't work either
sysEvents.keystroke("¯\\_("+ decode_utf8("\xE3\x83\x84") +")_/¯");
我爲什麼不認爲這是我之前,但不知道做了一個服務。我也會試試這個。謝謝! – Francisc0