How to detect PopClip source browser?

Hi @nick , I made this snippet extension to search google in a variety of ways. However, when I use this extension in a non-default browser, it still navigates to the default browser. I think this is because I’m opening the URL from Alfred instead of PopClip. Is there a way to detect that source browser so I can pass that to Alfred.

Any other ideas? I want to keep PopClip and Alfred workflows/extensions consolidated, so the implementation remains in one place and I just call that from other apps.

// # popclip
// name: My Google Search | ⌥ for Maps
// icon: iconify:fe:google
// lang: js
const query = encodeURIComponent(popclip.input.text);
if (popclip.modifiers.option) {
  popclip.openUrl("alfred://runtrigger/com.alfredapp.andy.customsearch/searchwithgooglemaps/?argument=" + query);  
} else {
  popclip.openUrl("alfred://runtrigger/com.alfredapp.andy.google.search/searchwithgoogle/?argument=" + query);
}

I’m suprprised that isn’t opening in Alfred because I would expect macOS to use Alfred to open alfred: urls. I’ll check to make sure PopClip is doing the right thing.

Anyway, you can specify a particular browser like this (docs):

popclip.openUrl("https://xkcd.com", {app: "com.brave.Browser"}); // open xkcd.com in Brave browser

No No, this is working as expected. PopClip does open Alfred URLs.

I guess I didn’t ask clearly. Let me give an example. Brave is my default browser. If I’m using Chrome, and I use the above snippet, it tells Alfred to open a URL, which Alfred opens in the default browser. What I want is a way for popclip to detect which browser the snippet trigger from and send the browser name to Alfred. Coz that’s how the default google search extension works.

1 Like

Ah, I see. You can access the bundle ID of the current application in the global string popclip.context.appIdentifier. You can then insert this into the alfred: URL string in whatever way Alfred needs.

1 Like