Possibility to make BTT as a default browser

Generally idea is about to make possible to set BTT as a default browser, and later on implement different logic based on link. Few examples:

  • User click link in messenger, BTT catch this request as it set as a default browser. In BTT user implemented logic which will checking domain and open link in required browser.
  • User click link in any app, dropdown menu appear with available browser. Together with WebView it will be possible to implement menu which will allow you to select browser to proceed with link.
  • User click youtube links and it open not in browser but in media player.

One of example of app here: https://github.com/johnste/finicky, but with power of BTT there will be much more possibilities.

Yes please. This would help in my quest to replace various utilities with just BTT!

Nice idea! I already have most of the required code in BTT anyways, I’ll definitely add this.

2 Likes

Is it possible to make this configurable? I'd rather not have something that I will never use in the 'open with' menus.

This is now functional in versions >= alpha 3.521

The setup works like this (documentation will be added soon):

1.) Go to the named & other triggers section and add a "Did Open URL" trigger.
2.) If you just want to choose which browser to use, assign the "Open URL / Open URL With Selection" action and enter {BTT_OPENED_URL} as url, also select the Browser to use:

If you want to do some more complex things you can assign the "Run Real Java Script" action and run a script based on the url and/or the application that opened the URL:

(async ()=> {

// this gets the url that shall be opened
let url = await callBTT('get_string_variable', {variable_name:'BTT_OPENED_URL'});

// in case you want to decide based on the app you can also get the app path from where it was opened
let appPath = await callBTT('get_string_variable', {variable_name:'BTT_OPENED_URL_FROM_APP_AT_PATH'});

let openScript = {
    launchPath: '/usr/bin/open',     
	parameters: '-b com.apple.Safari ' + url, 
};


await runShellScript(openScript);

returnToBTT(url+'-'+appPath);
})();
2 Likes

Hi @Andreas_Hegenberg, I tried the feature today on the production release (3.540) and tried to use the BTT_OPENED_URL_FROM_APP_AT_PATH do decide which Browser to open based on the app requesting to open a link.
I tested with Unite $ Spark, in both cases, I get "Undefined" in BTT_OPENED_URL_FROM_APP_AT_PATH (I used the script you shared in the documentation)
Is there something missing ?
(I just send the appPath to the url to debug and all I get is safari opened at https://undefined)

(async ()=> {

// this gets the url that was opened
let url = await callBTT('get_string_variable', {variable_name:'BTT_OPENED_URL'});

// in case you want to decide based on the app you can also get the app path from where it was opened
let appPath = await callBTT('get_string_variable', {variable_name:'BTT_OPENED_URL_FROM_APP_AT_PATH'});

// this will open safari with the given URL
let openScript = {
    launchPath: '/usr/bin/open',
    parameters: '-b com.apple.Safari https://' + appPath,
};


await runShellScript(openScript);

returnToBTT(url+'-'+appPath);
})();

Ahh I'm sorry, apparently I didn't upload the updated documentation. I have renamed that variable to BTT_OPENED_URL_FROM_APP

Works much better with the right variable :slight_smile:
Thanks a lot for your very quick answer.
Release after release, BTT is solving more problems for my usage, and every release it reminds me how much it was a good "investment" to buy a license !!
Most useful Mac app

1 Like

I'm trying this in BTT 3.553, but the links always open in the browser in which I clicked on them (as usual), even though I have set BTT to be the default browser (I'm trying to redirect certain links clicked in Safari to either Firefox or a Unite App).

How can I debug this?

EDIT: Looks like I misunderstood and this is "only" for links outside of a browser?

Correct, this just behaves like setting a different default browser. Link clicks inside the browser are handled by the browser - this would probably require browser extensions to change.

(When setting Chrome as default Safari will also not open Chrome when clicking a link :-))

2 Likes

Why can't I set BTT as default browser in System Preferences | General?

(For me it only offers Safari, Firefox, and Finicky, but not BTT)

Reason: I want to prevent Safari's constant nagging about not being the default browser

@Andreas_Hegenberg is it possible to use BTT to allow links from a SPECIFIC APP to always open in an a SPECIFIC BROWSER? e.g., my default browser on my Mac is Safari, however I want links specifically in Microsoft Word to always open with Chrome, NOT Safari :slight_smile:

@Andreas_Hegenberg Really appreciate this feature. It would be great if there were accompanying browser extensions like Choosy: Browser extensions so that regular browser navigation could also be overridden for certain domains. I know that's a big ask though.

This can't work because the BTT_OPENED_URL variable is not updated in this case ;-(

i already deleted my post. seems like i was mislead by some value that was still stored in BTT_OPENED_URL

but since you replied: isn't there a slicker way to do this from within chrome than having to use "trigger context menu item" > "copy link address" > "open url %@"?

the problem with this is great: when "right clicking" on a link in chrome it will automatically get selected. hence the variable %@ behaves quite buggy and most of the time tries to open the "selected text" rather than the "content from clipboard" which actually holds the desired URL.

is there a variable to only reference the clipboard content?

image

With current BTT versions you could create a dynamic variable in the "Automations & Named & Other Triggers" like this, which will always return the clipboard content.

let result = await callBTT('get_clipboard_content', {});
returnToBTT(result);

Then you can use that variable in the open url action:

1 Like

perfect. thanks a lot. i was looking for exactly that content on the btt documentation but couldn't find it. i searched for "variables" etc. Maybe worth adding this example to the docs?

Yep, dynamic variables are very new. I'll add them to the docs soon. The script example is already in the docs here Using Java Script (not JXA) · GitBook (folivora.ai)

1 Like

ps: can you by any chance extend that script real quick to do a regex matching? and if no match then return "EMPTY". i know how to write regexps, just wouldnt know how to add it to this script.

this way we could mimick the behaviour of "Did open …".

I think I don't understand, what are you trying to match?