====== macOS 新增頁面的捷徑 ====== 在 macOS 上/,(Windows 也有吧?),/用 Todoist 時,可以按快捷鍵即時叫出小輸入條來快速新增待辦事項,後來,如果我有想暫記的事情,也會先這樣存到 Todoist 上。如果新增 DokuWiki 頁面也能這麼簡單直接就好了! 後來首先使用了 DokuWiki 的 newpagetemplate + openas 兩個 plugin 做了新增頁面的表單(GHS 上的 diary:new)。前兩天發現它是將輸入的文字轉成 URL 參數後餵給瀏覽器來轉譯及開啟,所以就想到:那如果用 AppleScript 或 Automator 寫個應用程式,引導輸入必要欄位,或許可以讓新增頁面、捕捉想法的過程更快捷? ---- /^20191201^/【初步成果】「新增 tweet」: * 逐個小 dialog(input)輸入年、月、日、標題、標籤 * 將標題、標籤中的非 ASCII 字元轉譯為 URL 編碼後,開在預設瀏覽器(用 ''open location'')((本來以為可能會有字元需要被 escape 掉,不過編碼好就好了)) * /^20191202^/ 小改一個「新增 post」 參考: * [[https://www.urlencoder.org/|URL Encode and Decode - Online]] * [[https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/PromptforText.html#//apple_ref/doc/uid/TP40016239-CH80-SW1|Mac Automation Scripting Guide: Prompting for Text]]:很有用的初步寫碼參考,讓我確定要用 AppleScript 而不是 Automator,因為 Automator 好像沒有那麼容易寫 dialog?FIXME * [[https://discussions.apple.com/thread/2031330|Use default browser in custom Apple Scrip… - Apple Community]]:教我用很簡單的 ''open location'' * [[https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/EncodeandDecodeText.html#//apple_ref/doc/uid/TP40016239-CH51-SW1|Mac Automation Scripting Guide: Encoding and Decoding Text]](編碼方面的初步參考,但注意裡面的函式其實無法轉譯漢字。我甚至不確定能否順利轉譯其他字元,有可能只能處理歐美環境中的一些符號吧!) * 其他分享在網路上的 encoding 函式……大多沒什麼用 * ★[[https://gist.github.com/hytti/57d056852ff603cf9c9287414bdd595e|An AppleScript for encoding text for use in a URL (UTF8)]]\\ (這個函式才是真正可以順利轉譯包括漢字在內非 ASCII 字元的,我擷取的是 ''encode_'' 開頭的 3 個函式) * AppleScript 基本知識: * [[https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_variables.html|Variables and Properties]] * [[https://en.wikibooks.org/wiki/AppleScript_Programming/Numbers_and_strings|AppleScript Programming/Numbers and strings]] ===== 改進 ===== * 單頁式的 dialog 一次顯示所有的欄位,確認好再導向 DokuWiki 新增頁面,甚至以後可能就權充桌面 client * [[https://apple.stackexchange.com/questions/337256/custom-dialog-box-in-automator|applescript - Custom dialog box in Automator? - Ask Different]] * ☞ [[https://www.macosxautomation.com/applescript/apps/Script_Libs.html#DialogToolkit|Dialog Toolkit]]