Opening custom extension's URL with a non-default web browser

I’m using some basic extension snippets, which has name, icon, and URL.

And I’m wondering if it is possible for a custom extension to open its custom URL with a browser that is not system-default.

1 Like

You can always make Choosy your default browser. It’s a really powerful way to use different browsers for different sites, or under different circumstances, etc.

1 Like

You can indeed:

#popclip
name: URL app example
javascript: |
  popclip.openUrl('https://xkcd.com', {app: 'com.brave.Browser'})
2 Likes

Thanks! But I see an error message when I try to import it. The error message is: "JS: SyntaxError: Invalid character '\u2018` (line 1)
Do you have an idea of what causes the error in the following script?

#popclip
name: [name]
icon: square filled [name]
javascript: |
  popclip.openUrl('https://[website's name].org/v2/search?queryString=***&clusterResults=on&stickyFacetsChecked=on&baseScope=sz%3A36213', {app: ‘Google Chrome’})

Oddly enough that snippet is actally crashing my PopClip! Ooof…

/u2018 is unicode for a left quotation mark … perhaps you have smart quotes turned on in your editor? It has to be a plain old vertical single quote.

And of course your placeholder text website's name has a ' in it which is terminating the string eartly.

Otherwise looks fine except you need to specify the app as a bundle id e.g. com.google.Chrome.
(For finding bundle ID see also here)

1 Like

Nick, you were right! It was smart quotes. And I also updated the bundle id. Now it is successfully imported and works, but the problem is that custom keyword *** does not reflect the selected portion of texts.
So no matter what text I choose, the search keyword is ***.

Do you have any idea?

Ah yes, I should have caught that. The *** shorthand only works in a url: field of the extension. In javascript you will have to manually build the string.

For example:

popclip.openUrl(`https://xyz.org/?q=${encodeURIComponent(popclip.input.text)}`)

Notes:

1 Like

Thanks, Nick.
Then, what portion of that code needs to replace ***?

This part: ${encodeURIComponent(popclip.input.text)}

If you want to post an example you are trying to get working (not with placeholders), I can correct it.

Thanks Nick,

Since I can’t make it work, please correct these two extensions:

# popclip
name: GCTS Library
icon: square filled GC
javascript: |
  const term = encodeURIComponent(popclip.input.text)
  const url = `https://gordonconwell.on.worldcat.org/v2/search?queryString=${term}&clusterResults=on&stickyFacetsChecked=on&baseScope=sz%3A36213`
  popclip.openUrl(url, {app: 'com.google.Chrome'})

# popclip
name: TIU Library
icon: square filled TIU
javascript: |
  const term = encodeURIComponent(popclip.input.text)
  const url = `https://i-share-tiu.primo.exlibrisgroup.com/discovery/search?institution=01CARLI_TIU&vid=01CARLI_TIU:CARLI_TIU&tab=LibraryCatalog&search_scope=MyInstitution&mode=Basic&displayMode=full&bulkSize=10&highlight=true&dum=true&query=any,contains,${term}&displayField=all&scopeSelecter=LibraryCatalog&pcAvailabiltyMode=`
  popclip.openUrl(url, {app: 'com.google.Chrome'})

Edited in the post, enjoy!

1 Like

I use OpenIn which is similar to Choosy and yet PopClip will open the extension’s URL not respecting the rule I set up. :confused:

Hi, can you please post the specific extension code that you are having trouble with?

Sorry @nick, for some reason I completely missed your reply.

Here’s an extension code example:

#popclip extension to search Forest Admin
    name: Forest Admin - Org
    icon: search filled forg
    url: https://app.forestadmin.com/Slite/Production/Support/data/organizations/index?filter=%7B%22type%22%3A%22or%22%2C%22conditions%22%3A%5B%7B%22operator%22%3A%22is%22%2C%22value%22%3A%22?q=***%22%2C%22fieldName%22%3A%22id%22%2C%22subFieldName%22%3Anull%2C%22embeddedFieldName%22%3Anull%7D%2C%7B%22operator%22%3A%22is%22%2C%22value%22%3A%22?q=***%22%2C%22fieldName%22%3A%22domain%22%2C%22subFieldName%22%3Anull%2C%22embeddedFieldName%22%3Anull%7D%5D%7D

Thank you! :pray:

That will open in the default browser – which I guess is Choosy on your system? What exactly is going wrong for you?

My default browser is OpenIn. In OpenIn, I have a rule setup to open links from this domain in Chrome. (I use Safari for everything except for some websites.)

If I select some text anywhere and use this extension, it will correctly open Chrome. However, what I need to do is select some text in Safari to launch the extension (that’s my use case) and it will open the link in Safari instead of Chrome.

Does that make sense?

Got it.

PopClip uses the default system browser except when being invoked from a different browser. In those case it stays in that browser.

You’ll need to force PopClip to use OpenIn even when invoking from a browser. We can take the approach as shown in the thread above. Like this:

// #popclip extension to search Forest Admin
// name: Forest Admin - Org
// icon: search filled for
// language: javascript
const query = encodeURIComponent(popclip.input.text);
const url = `https://app.forestadmin.com/Slite/Production/Support/data/organizations/index?filter=%7B%22type%22%3A%22or%22%2C%22conditions%22%3A%5B%7B%22operator%22%3A%22is%22%2C%22value%22%3A%22?q=${query}%22%2C%22fieldName%22%3A%22id%22%2C%22subFieldName%22%3Anull%2C%22embeddedFieldName%22%3Anull%7D%2C%7B%22operator%22%3A%22is%22%2C%22value%22%3A%22?q=${query}%22%2C%22fieldName%22%3A%22domain%22%2C%22subFieldName%22%3Anull%2C%22embeddedFieldName%22%3Anull%7D%5D%7D`;
popclip.openUrl(url, {app: 'app.loshadki.OpenIn-setapp'});

(The above block is an extension snippet — select it then click “Install Extension” in PopClip.)

If you’re using the Setapp edition of OpenIn you’ll want the bundle id app.loshadki.OpenIn-setapp instead.

Ah okay, that’s good to know!

I tried what you suggested but the still gets opened in Safari instead of OpenIn. (I copied the bundle id of the Setapp version.)

That’s odd. It’s working for me. Are you super sure you are invoking the right version of the snippet? Try deleting any the old ones and install again.

I was sure but I was obviously wrong because it’s now working.

However I’m now having trouble coming up with the correct URL again… My search term should be replaced by ***, correct? I did many tries but I can’t get my select text to be the query.

Sorry for asking something so basic. I appreciate your help!