Keyboard Maestro复制Markdown格式

1. 前言

之前在 Chrome 浏览器里,有 Copy as Markdown 的插件 1,可以快速复制 Markdown 格式 — [Tab名](link)

用 Safari 浏览器外加 Tampermonkey 2 后,虽然也可以用一些脚本实现复制 Markdown 格式,但是效果不是很好,而且有时候粘贴不出想要的内容。

搜索🔍 Keyboard Maestro 复制 Markdown 格式,发现了 「用 Keyboard Maestro 做一个文本格式转换工具箱 - 少数派」 3,里面的部分工具🔧能够实现想要的功能:快速复制 Markdown 格式 — [Tab名](link)

2. 步骤

  1. 下载 GitHub 文件 keyboard-maestro-gallery/Convert Toolbox/链接格式转换 Safari.kmmacros

  2. 只用其中的 Paste Markdown Link from Safari Tabs Macro 即可,AppleScript 为 4

tell application "Safari"
    -- Initialize
    set tabNames to {}
    set tabURLs to {}
    set frontName to name of front document
    
    -- Collect the tab names and URLs from the top Safari window
    set topWindow to window 1
    set topTabs to every tab of topWindow
    repeat with t in topTabs
        set end of tabNames to name of t
        set end of tabURLs to URL of t
    end repeat
end tell

-- Display a list of names for the user to choose from
tell application "System Events"
    set activeApp to name of first application process whose frontmost is true
    activate
    choose from list tabNames with title "Safari Tabs" default items frontName
    if result is not false then
        set nameChoice to item 1 of result
    else
        return
    end if
end tell

-- Return the URL of the selected tab
tell application activeApp to activate
repeat with t from 1 to the count of tabNames
    if item t of tabNames is nameChoice then return "[" & (item t of tabNames) & "]" & "(" & (item t of tabURLs) & ")"
end repeat
  1. 可以重新设置自己习惯的快捷键。

彩蛋🥚: 少数派部分文章合集

3. 参考

  1. Copy as Markdown - Chrome Web Store
  2. Tampermonkey
  3. 用 Keyboard Maestro 做一个文本格式转换工具箱 - 少数派
  4. keyboard-maestro-gallery/Convert Toolbox/链接格式转换 Safari.kmmacros