copy as markdown link ?

Is it possible to copy a website in chrome as a markdown link ? thank you

Hi @lucas222,

Here’s a quick approach using JavaScript for Automation (JXA). I’m assuming a couple of things:

  1. You want to copy the URL of the current (frontmost) tab in Chrome, rather than a hyperlink within a page.

  2. You want to use a keyboard shortcut to copy the website URL formatted in Markdown.

JavaScript for Automation (JXA) Code

Here’s the complete script that:

  1. Gets the title of the frontmost Chrome tab

  2. Gets the URL of the frontmost Chrome tab

  3. Creates a Markdown link of the form:

[Title](https://example.com)
  1. Copies that Markdown link to your clipboard
  2. Returns the Markdown link text (so you can see it in BTT’s script result view)
(() => {
    // Allow usage of standard additions such as setTheClipboardTo
    const app = Application.currentApplication();
    app.includeStandardAdditions = true;

    // Reference Google Chrome
    const chrome = Application("Google Chrome");

    // Get the frontmost Chrome window and its active tab
    const frontWindow = chrome.windows()[0];
    const activeTab = frontWindow.activeTab();

    // Get the title and URL
    const title = activeTab.title();
    const url = activeTab.url();

    // Create the Markdown link string
    const markdownLink = `[${title}](${url})`;

    // Copy the Markdown link to the clipboard
    app.setTheClipboardTo(markdownLink);

    // Return the Markdown link (useful for debugging in BTT’s script result view)
    return markdownLink;
})();

BetterTouchTool JSON Configuration

Below is the JSON for a single keyboard shortcut trigger with an async JXA action in BTT. If you copy and then paste this JSON into BTT, it’ll create:

• A trigger of type keyboard shortcut (⌃+C, in this example)

• An action of type “Run JavaScript for Automation (async in background)” action, which executes the above code.

[
  {
    "BTTActionCategory" : 0,
    "BTTLastUpdatedAt" : 1736602719.319443,
    "BTTTriggerType" : 0,
    "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
    "BTTUUID" : "25622F7C-C25C-471D-9A3C-EE2F6D960386",
    "BTTPredefinedActionType" : 366,
    "BTTPredefinedActionName" : "Empty Placeholder",
    "BTTAdditionalConfiguration" : "1835049",
    "BTTKeyboardShortcutKeyboardType" : 2302,
    "BTTTriggerOnDown" : 1,
    "BTTLayoutIndependentChar" : "c",
    "BTTEnabled" : 1,
    "BTTEnabled2" : 1,
    "BTTShortcutKeyCode" : 8,
    "BTTShortcutModifierKeys" : 1835008,
    "BTTOrder" : 1,
    "BTTAutoAdaptToKeyboardLayout" : 0,
    "BTTAdditionalActions" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1736603213.604872,
        "BTTTriggerParentUUID" : "25622F7C-C25C-471D-9A3C-EE2F6D960386",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
        "BTTUUID" : "08705B5F-A16C-4E52-B35E-D259213C2410",
        "BTTPredefinedActionType" : 252,
        "BTTPredefinedActionName" : "Run JavaScript for Automation (async in background)",
        "BTTAdditionalActionData" : {
          "BTTScriptType" : 1,
          "BTTAppleScriptString" : "(() => {\n    // Allow usage of standard additions such as setTheClipboardTo\n    const app = Application.currentApplication();\n    app.includeStandardAdditions = true;\n\n    // Reference Google Chrome\n    const chrome = Application(\"Google Chrome\");\n\n    // Get the frontmost Chrome window and its active tab\n    const frontWindow = chrome.windows()[0];\n    const activeTab = frontWindow.activeTab();\n\n    // Get the title and URL\n    const title = activeTab.title();\n    const url = activeTab.url();\n\n    // Create the Markdown link string\n    const markdownLink = `[${title}](${url})`;\n\n    // Copy the Markdown link to the clipboard\n    app.setTheClipboardTo(markdownLink);\n\t\n\t// Return the Markdown link (useful for debugging in BTT)\n\treturn markdownLink\n})();",
          "BTTAppleScriptUsePath" : false,
          "BTTAppleScriptRunInBackground" : true,
          "SelectedAction" : 252,
          "BTTScriptLocation" : 0
        },
        "BTTInlineAppleScript" : "(() => {\n    // Allow usage of standard additions such as setTheClipboardTo\n    const app = Application.currentApplication();\n    app.includeStandardAdditions = true;\n\n    // Reference Google Chrome\n    const chrome = Application(\"Google Chrome\");\n\n    // Get the frontmost Chrome window and its active tab\n    const frontWindow = chrome.windows()[0];\n    const activeTab = frontWindow.activeTab();\n\n    // Get the title and URL\n    const title = activeTab.title();\n    const url = activeTab.url();\n\n    // Create the Markdown link string\n    const markdownLink = `[${title}](${url})`;\n\n    // Copy the Markdown link to the clipboard\n    app.setTheClipboardTo(markdownLink);\n\t\n\t// Return the Markdown link (useful for debugging in BTT)\n\treturn markdownLink\n})();",
        "BTTKeyboardShortcutKeyboardType" : 0,
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTShortcutKeyCode" : -1,
        "BTTOrder" : 690,
        "BTTAutoAdaptToKeyboardLayout" : 0
      }
    ]
  }
]
1 Like

thank you so much ! extremely kind of you !!

1 Like