17

I recently changed my default browser from Chrome to Safari, but I still do development in Chrome. I'd like URLs in iTerm2 to open up in Chrome, but now they open in Safari since its my system default.

Is it possible to change this?

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104

3 Answers3

17

You can add a Context Menu option for the smart selection of a URL for Chrome via the Edit Actions of the Smart Selection Rules (within a given profile) with a parameter of:

open -a "Google Chrome" \0

enter image description here

Once you do this, this action will override the built-in default of using the system defined app (Safari in your case).

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thanks! I found the window and added the option, but it doesn't seem to be working. Is there something I need to do to trigger a config reload? – Sam Selikoff Oct 18 '17 at 13:48
  • @SamSelikoff I don't believe you have to do anything special (assuming you change the setting in a profile that you currently have open in a shell, but you can try restarting iTerm to test. – SushiHangover Oct 18 '17 at 13:51
  • Now I'm seeing that this is supposed to change the context menu. I was hoping to get the default +click to open the URL in Chrome. Is that possible? – Sam Selikoff Oct 18 '17 at 13:52
  • @SamSelikoff Yes, it will add a context menu, **but** it also overrides the default app url handling. Make sure that you are highlighting the `HTTP URL` Smart Selection Rules entry before clicking on the `Edit Action` button. It works, I have urls opening in Firefox (for dev work) and my default browser is Safari. I also register custom url schemes so Chrome opens (i.e. `chrome-devtools://` based urls) – SushiHangover Oct 18 '17 at 14:02
  • This sounds just like what I want but I'm still having trouble. When I hold ⌘, URLs underline in blue. There's an option under "Pointer" that says "⌘-Click Opens Filename/URL (Semantic History)". If I uncheck that, URLs no longer highlight or open. So I can't seem to get the Smart Selection Rules to have any effect. The Smart Selection area says "Quad-click selects a string under the cursor..." Does it mean something other than ⌘+click? Also, I'm using tmux if it matters. – Sam Selikoff Oct 18 '17 at 14:11
  • @SamSelikoff Kind-of confused, you are not changing the existing Smart Selection rules, but adding an `Action` to the existing `HTTP URL` one. (reload the defaults if needed to start over, `Load Defaults`). Highlight `HTTP URL` and click `Edit Actions`, add an entry as shown in my answer. Save it and go to an iTerm window running the `Profile` that you added the HTTP Url Action to, and ⌘+click an url. – SushiHangover Oct 18 '17 at 14:18
  • I did exactly this, unfortunately I'm having the same result. :( – Sam Selikoff Oct 18 '17 at 14:22
  • @SamSelikoff I'm running Build `3.1.3` the latest version if that might make a difference(?) – SushiHangover Oct 18 '17 at 14:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157010/discussion-between-sam-selikoff-and-sushihangover). – Sam Selikoff Oct 18 '17 at 14:26
  • I was not using the profile I had edited. (I only had one profile, so assumed it was being used for all sessions). I clicked Shell > New Tab and it worked! Thank you! – Sam Selikoff Oct 18 '17 at 14:28
  • @SamSelikoff hahaha, Yes, Profile specific! You can get crazy and have different browsers for different Profiles, but dealing with 3 browsers for different types of URL schemes in one profile is enough for me :-) – SushiHangover Oct 18 '17 at 14:34
4

If you are trying to open http://localhost:#PORT, it might be necessary to add in Smart Selection Rules a new rule with Regular Expression of https?://localhost(:[a-zA-Z0-9]+)? and Precision of Very High, before applying @SushiHangover's answer.

The default HTTP URL rule does not appear to recognize http://localhost well.

Agboh
  • 41
  • 3
-1

You should specify which browser you want to open that URL by, you can try the below command:

open -a "/Applications/Google Chrome.app" <your URL>

Yoyo
  • 165
  • 2
  • 4