在Obs089-Quick Settings by QuickAdd Script介紹了透過QuickAdd彙總常用設定再以Advanced URI開啟設定視窗的方法,但因為QuickAdd的概念與操作比較繁複,不曉得有多少朋友有正確的設定起來?因為有新的Open Plugin Settings外掛可以簡化相同功能,因此今天特別再來介紹新的方法:
- 第一個作法是透過Open Plugin Settings來產生命令,再用Templater Hotkeys設置快捷鍵。
- 第二個作法和先前的作法一樣使用Advanced URI外掛來開啟設定設定視窗,但不再使用QuickAdd而改用Templater Hotkeys。
先介紹兩種作法的Templater腳本,最後再介紹Templater Hotkeys的綁定步驟。
1. Open Plugin Settings Plugin
1.1. Open Plugin Settings安裝與設定
- 安裝並啟用Open Settings外掛
- 新增需要快速的外掛
- 新增後的設定會添加成命令,最常使用的外掛設定即可透過命令綁定快捷鍵
1.2. 撰寫Templater腳本
- 在Templater資料夾裡建立 Cmd-open-settings.md,內容如下
- JSON格式:
{json} "顯示外掛名稱": "open-plugin-settings:外掛命令代碼"
<%*
// Hotkey: Alt+S
// Open settings plugin必須先設定
let oSettings = {
"BRAT": "open-plugin-settings:obsidian42-brat", //"obsidian42-brat:BRAT-AddBetaPlugin",
"QuickAdd": "open-plugin-settings:quickadd",
"Open-plugin": "open-plugin-settings:open-plugin-settings",
"Other settings":"open-plugin-settings:open-other-plugin-settings",
"Commander": "cmdr:open-commander-settings", //"open-plugin-settings:cmdr"
"Keyshots": "keyshots:open-keyshots-settings-tab",
"Style settings": "obsidian-style-settings:show-style-settings-leaf",
"Settings": "app:open-settings"
};
let aKeys = Object.keys(oSettings);
let aValues = Object.values(oSettings);
let sValue = await tp.system.suggester(aKeys, aValues, false, "選擇要設定的外掛"); // (displays, values,...)
if (!sValue) return;
// console.log(sValue);
await app.commands.executeCommandById(sValue);
-%>
[!QUESTION]+ 如何得知某個外掛的命令代碼(Command ID)呢?
- 方法1:查看 vault/.obsidian/plugins/資料夾外掛的資料夾名稱,此名稱即為其外掛命令代碼
- 方法2:vault/.obsidian/plugins/open-plugin-settings/data.json,id 欄位值即為外掛命令代碼
[!TIP]+ 技巧:列出所有命令的簡單方法
- 按Ctrl+Shift+I進入開發工具Console
- 輸入並執行
{js} app.commands.listCommands()
- 檢查Console,並點擊展開
- 點擊再按Ctrl+S複製到系統剪貼簿以方便查看
1.3. 綁定快捷鍵
- 特定的Open Plugin Setting: 設定→快捷鍵→搜尋Open Plugin Settings的某個項目,綁定快捷鍵,例如Alt+S
- 設定→Community Plugins→搜尋 Templater→Templater Hotkeys→新增資料,找到Cmd-open-settings
- 設定→快捷鍵→搜尋 Cmd-open-settings,綁定快捷鍵,例如Alt+S
2. Advanced URI Plugin
2.1. 撰寫Templater腳本
- 在Templates資料夾裡建立 Cmd-open-settings-by-uri.md,內容如下
- oSettingsJson 冒號左側是顯示在對話窗的文字
- oSettingsJson 冒號右側是settingid或命令代碼或檔名
- settingid:用
{js} window.open("obsidian://advanced-uri?vault=VAULT&settingid=...")
開啟設定視窗 - 含有
>
:其右側是設定段落(settingsection),例如編輯器設定內的行為(Behavior)即段落,必須與畫面內的值大小寫相同 - 以
!
開頭:其右側是命令代碼 (用{js} app.commands.executeCommandById()
執行命令) - 以
@
開頭:其右側是筆記檔名(含路徑)
- settingid:用
<%*
/**
* Using Advanced URI Plugin to open specified settings.
* settingid: Normally the plugin's folder name. We can find the correct id in plugin's manifest.json
* Hotkey: Alt+S
* Ref: Obsidian Advanced URI: https://vinzent03.github.io/obsidian-advanced-uri/actions/settings_navigation
*/
let oSettingsJson = {
"Core: Appearance": "appearance",
"Core: Community plugins": "community-plugins",
"Core: Plugin browser": "plugin-browser",
"Core: Theme browser": "theme-browser",
"Core: Hotkeys": "hotkeys",
"Core: Editor > Behavior": "editor>Behavior", // ">" indicates settingsection; 行為
"Plugin: BRAT": "obsidian42-brat>Beta Plugin List",
"Plugin: QuickAdd": "quickadd",
"Plugin: Open-plugin settings": "open-plugin-settings",
"Plugin: Commander": "cmdr",
"Plugin: Keyshots": "keyshots",
"Plugin: Soundscapes": "soundscapes",
"Plugin: Style settings": "obsidian-style-settings",
"Plugin: Settings": "app:open-settings",
"Plugin: Other settings":"!obsidian42-brat:BRAT-opentPluginSettings", // "!" indicates executes by command ID
"File: Cmd-open-settings-by-uri.md":"@010-Templates/Cmd-open-settings-by-uri.md", // "@" indicates opens file (with path)
//"Other settings":"!open-plugin-settings:open-other-plugin-settings"
};
let aDisplays = Object.keys(oSettingsJson);
let aValues = Object.values(oSettingsJson);
let sValue = await tp.system.suggester(aDisplays, aValues, false, "選擇要設定的外掛"); // (displays, values,...)
if (!sValue) return;
const VALUT = "Your-vault";
//console.log(sValue);
if (sValue.startsWith("!")) { // Command ID
sValue = sValue.substring(1);
await app.commands.executeCommandById(sValue);
} else if (sValue.startsWith("@")) { // Open file
sValue = sValue.substring(1);
const oFile = await app.vault.getAbstractFileByPath(sValue)
await await app.workspace.getLeaf("tab").openFile(oFile);
} else if (sValue.contains(">")) { // Handle settingsection
let iIndex = sValue.indexOf(">");
let sID = sValue.substring(0, iIndex);
let sSection = sValue.substring(iIndex+1);
window.open("obsidian://advanced-uri?vault=" + VAULT + "&settingid=" + sID + "&settingsection=" + sSection);
} else {
window.open("obsidian://advanced-uri?vault=" + VAULT + "&settingid=" + sValue);
}
-%>
2.2. 綁定快捷鍵
- 設定→Community Plugins→搜尋 Templater→Templater Hotkeys→新增資料,找到Cmd-open-settings-by-uri
- 設定→快捷鍵→搜尋 Cmd-open-settings-by-uri,綁定快捷鍵,例如Alt+S
3. 操作
- 按Alt+S會彈出外掛設定選擇對話窗,擇一執行
- Other settings會再出現Open Settings以外的外掛選單
4. 💡 相關鏈接
✅ obsidian-open-settings: https://github.com/Lisandra-dev/obsidian-open-settings
✅ Obsidian Advanced URI > Settings Navigation https://vinzent03.github.io/obsidian-advanced-uri/actions/settings_navigation
✅ Obs089 | QuickAdd巨集快速開啟設定視窗-Step by step;直接使用window.open: https://www.youtube.com/embed/g-rtSlHao0g
5. 教學影片
##
您可能也會有興趣的類似文章
- [Obs#88] 綜合練習:快速設定的6種方法─使用8個Obsidian外掛 (0則留言, 2022/05/21)
- [Obs-74] 和外掛相關的外掛─BRAT: 搶先體驗未上架外掛;Settings Search: 加速搜尋外掛設定 (0則留言, 2022/03/05)
- Obs139|5個方便維護Properties的外掛:Linter、TagMany、File Cooker、Tag Wrangler、Templater Hotkeys (0則留言, 2023/09/10)
- [Obs#58] 快速開啟常用筆記的方法 (0則留言, 2021/10/23)
- Obs127|用Templater Hotkeys簡化Obsidian自動化腳本,詳解4個腳本範例 (0則留言, 2023/05/05)
- Obs140|Obsidian進階全文檢索與複製結果的外掛-Query Control、Better Search View、Float Search、Text Expand、File Cooker (0則留言, 2023/09/15)
- Obs124|跳,跳,跳乎伊勇!Obsidian用書籤和標籤快速在檔案間跳轉 (1則留言, 2023/04/23)
- Obs146|Obsidian彙總常用說明網站的助手:HelpMate (0則留言, 2023/12/03)
- [Obs#55] 建立新筆記的模板設定-Calendar, Templater與QuickAdd (0則留言, 2021/10/09)
- Obs149-左邊長筆記,右邊卡片的編輯佈局:Query Control, Note Gallary (0則留言, 2024/01/28)
- [Obs#56] 快速新增靈感/閃念筆記(Fleeting Note)的3種方法 (0則留言, 2021/10/10)
- Obs141|Opener與Open Gate外掛-開啟在新分頁與開啟網頁+內嵌網頁 (0則留言, 2023/09/24)
- [OBS#32] templater: 無限擴充可能的第三方樣板外掛 (0則留言, 2021/04/10)
- [Obs#95] Obsidian v0.16對於使用介面的強化🚀 (0則留言, 2022/09/04)
- [Obs#35] Buttons外掛開啟筆記自動化操作契機 (0則留言, 2021/04/23)