Can Keyboard Maestro detect browser profile?

Chromium based browser already have 'profiles' feature for a while now. Safari launched 'profiles' feature with Sonoma. So I started using profiles feature in safari as well as chromium based browsers.

Example 1, I have a macro that disables vim extension on brave browser (this is based on a condition that brave browser is at the front, before running the macro) when it disables, it saves a state in variable x as 'disabled'. When it enables, it saves the state as 'enabled'. Problem occured when I started using different profile in brave. I am using vim in that profile as well. and their enabled and disabled state may not match. How do I handle this problem?

Example 2, I would like to have a set of bookmarks in 'prompt with list' action. Different profiles (be it inside safari or inside chrome) would have different set of bookmarks. I need KM to detect which profile is at the front and accordingly give me the list of bookmarks. How do we handle this?

Chrome wrecked my Mac once before, so I'll never install it or any Chromium browser again, but I'll throw my two cents into the ring here. (There's a 30% chance that I'm wrong because this topic is on the edge of my knowledge.)

I see two possible different paths for your first problem. In any case, here's the crucial issue: the information about the profile change has to reach your macro, so either:

Path#1. The chromium browser has to update macOS with a notification that it has changed its profile, which the KM Engine can query in some way (preferably an API to receive notification) and then trigger your macro, or
Path#2. Your macro will have to "poll" Chrome to determine if it has changed its profile.

Regarding #1 - I have no idea whether "chromium" informs macOS about a change in its profile, and I have no idea whether macOS has an API that lets the KM Engine get notified of such a change. But I'm not hopeful.

Regarding #2 - I think it's quite possible for your KM macro to "poll" your browsers storage (or maybe the screen) to see which profile is in use. It's probably best if it can poll the browsers storage. Can you identify the name of the browser's config file that contains the choice of profile? This is something that KM could poll every so often (for example, whenever the application launches or closes, and maybe once per minute while it's open.) I googled this for you, and found that the Brave files are stored in here:

macOS: /Users/[You]/Library/Application Support/BraveSoftware/

Try looking in the files in that folder and find the file that contains the name of the profile that was selected. If you can find that, I can probably help you.

1 Like

How did you get to know it was chrome?

This is some high level shit for me because I am non technical person. Me using KM itself is an achievement for me :joy:

This is possible in case of safari because the name of the profile is always on display and we can use found image condition. However I have realised if the image already exists on the screen when the action is triggered, it fails to detect the image. So it is futile to use.

I got these search results when I searched for a name of one of my profiles in brave browser. The 2 text files you can see in the screenshot, i opened them and searched again for the same keyword, i found 1 match.

can we take further from here?

I could see evidence of Chrome still on my computer after uninstalling it, and I googled the problem and someone explained that Chrome was still partially installed and using a lot of CPU. When I finally found a way to uninstall it, my performance was back up to normal. This was probably five years ago, so I'm not able to find the web page anymore.

That's fine. Everyone is welcome here.

I don't think I understand "if the image already exists on the screen... it fails to detect the image." It sounds like you're saying it never works.

Image detection is something KM is very good at, but it should usually be considered undesriable when there are better ways like checking config files.

It's not the files with profile names that we want. It's the file that contains the name of the currently selected profile. I wouldn't expect that the actual profile files will contain this. I'm not sure which file that would be, but I just did a quick google which said this may be what you need to look inside:


I don't need to see the contents, in case there are any personal names in there that you don't want me to see. But tell me if you see anything in there that looks like the current profile name. Then, maybe to prove you found it, change the Brave profile and check if the file's contents have changed.

With the %FrontBrowser% token and AppleScript, we can determine information about the frontmost browser window, regardless of how many browsers/windows/profiles you have open at once.

This macro works for Safari, Chrome, and Brave:

Get front browser profile.kmmacros (7.4 KB)

Macro image

Some notes:

  • The profile information for Chrome and Brave were easily accessible, so this could be easily modified to work with other Chromium-based browsers.
  • For Safari the profile was a bit tricker to find, so it requires a Search and Replace and a percent-decode Filter. This should work, but it's less likely to remain reliable over time and across browser versions and Safari-based variants. If someone could find (or if Apple introduces) a more direct way to get the profile, this could be improved.
1 Like

You are awesome man. Thanks for sharing this. And also sharing the possibility of safari macro not being reliable.

You mean versions that automatically come as safari or mac os updates?

I might tag you again if it stops working :smile: May be you'd have some new trick up your sleeve that time.

Let's hope people actually see this and someone would have something to improve it. It also depend on how many people have this as their use case. Because safari 'profile' feature is new. Let's hope for the best :crossed_fingers:

@Airy Look, we found a solution :smiley:

1 Like

Yes, I meant that a future update to Safari could change the results. Honestly though, I think that's pretty unlikely to happen. I just wanted to point out the shakiest part of the macro, but chances are it stays working for a long time.

Go for it! On the off chance Apple does something to break this solution, I'm sure it wouldn't be too hard to put it back together.

1 Like