Quantcast
Channel: 簡睿隨筆
Viewing all articles
Browse latest Browse all 897

Obs153|快速開啟外掛設定的方法;使用Open Plugin Settings與Advanced URI,透過Templater Hotkeys綁定快捷鍵

$
0
0

Obs089-Quick Settings by QuickAdd Script介紹了透過QuickAdd彙總常用設定再以Advanced URI開啟設定視窗的方法,但因為QuickAdd的概念與操作比較繁複,不曉得有多少朋友有正確的設定起來?因為有新的Open Plugin Settings外掛可以簡化相同功能,因此今天特別再來介紹新的方法:

  1. 第一個作法是透過Open Plugin Settings來產生命令,再用Templater Hotkeys設置快捷鍵。
  2. 第二個作法和先前的作法一樣使用Advanced URI外掛來開啟設定設定視窗,但不再使用QuickAdd而改用Templater Hotkeys。

先介紹兩種作法的Templater腳本,最後再介紹Templater Hotkeys的綁定步驟。

1. Open Plugin Settings Plugin

1.1. Open Plugin Settings安裝與設定

  1. 安裝並啟用Open Settings外掛
  2. 新增需要快速的外掛
  3. 新增後的設定會添加成命令,最常使用的外掛設定即可透過命令綁定快捷鍵

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. 方法1:查看 vault/.obsidian/plugins/資料夾外掛的資料夾名稱,此名稱即為其外掛命令代碼
  2. 方法2:vault/.obsidian/plugins/open-plugin-settings/data.json,id 欄位值即為外掛命令代碼

[!TIP]+ 技巧:列出所有命令的簡單方法

  1. Ctrl+Shift+I進入開發工具Console
  2. 輸入並執行 {js} app.commands.listCommands()
  3. 檢查Console,並點擊展開
  4. 點擊再按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()執行命令)
    • @ 開頭:其右側是筆記檔名(含路徑)
<%*
/**
 * 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

✅ 腳本1: https://gist.githubusercontent.com/emisjerry/0a1d859d5ea961f21b68ad6025e1b6a3/raw/9e50b1cfdf89c236d70d2a2e3d88991f1c4b1a58/Cmd-open-settings.md

✅ 腳本2: https://gist.githubusercontent.com/emisjerry/5fecaae7a72a72b15daf263c8f6e49a4/raw/6b353707840b6f7116e55abdcc9c674d9c1147c5/Cmd-open-settings-by-uri.md

5. 教學影片

##

您可能也會有興趣的類似文章


Viewing all articles
Browse latest Browse all 897

Trending Articles