Detecting Mastodon Links with BetterTouchTool

Just an update, I finally figured out a way to do this using BetterTouchTool as my default browser.

I have two “Did Open URL” automation triggers setup looking for different wildcard URL patterns.

The first one is looks for profile url and the second looks for post urls.

Profile URL Wildcard Pattern:

*://*.*/@*

Post URL Wildcard Pattern:

*://*.*/@*/[0-9]*

If a URL matches either pattern it runs a javascript using the “Run Real Javascript” action that replaces “http” and https" with “mona://” and runs a shell script that opens the modified URL in Mona.

(async () => {
    // This gets the URL that was opened
    let url = await get_string_variable({ variable_name: 'BTT_OPENED_URL' });

    // Replace "https" and "http" with "mona://"
    let modifiedUrl = url.replace(/^https?/, 'mona');

    // This will open the specified app with the modified URL
    let openScript = {
        launchPath: '/usr/bin/open',
        parameters: `-u;;${modifiedUrl};;-a;;Mona`
    };

    await runShellScript(openScript);

    returnToBTT(modifiedUrl);
})();