Clickable hyperlinks in Terminal.app on zsh

Mac M1

Monterey 12.2.1 (I am aware this needs updating; doing so at current location unfeasible)

Terminal Version 2.12 (443)

zsh 5.8 (x86_64-apple-darwin21.0)


This is partly a zsh/ASNI escape sequence question, however I am confident that people in this community may have faced this issue, and it is specifically a frustration configuring Terminal.app with zsh.


I want to print out a hyperlink like below (using a language called Dart).

This works in VSC's terminal emulator, producing a clickable, underlined hyperlink, but sadly it does not work if run in Terminal.app (both using zsh).


Is there a particular way to configure specific to this OS that folk here have encountered?

Terminal-->Preferences has no option.


EXAMPLE CODE:


void printClickableLink(String text, String url) {
  if (Platform.isWindows) {
    stdout.write('$text ($url)');
  } else {
    stdout.write('\u001B]8;;$url\u001B\\$text\u001B]8;;\u001B\\');
  }
}


MacBook Air 13″, macOS 12.2

Posted on Jun 8, 2023 7:06 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 8, 2023 8:18 AM

You might try a different terminal emulator.


AFAIK, Apple Terminal.app doesn’t scan for and doesn’t offer clickable hyperlinks in text.


Neither did a DEC VT terminal, nor does DECterm. 🤭


Command-line interfaces don’t generally tend to have GUI mechanisms, either.


What sort of macOS command-line UI are you building?


What’s this code intended to do? Esc ] 8 ; ; — I don’t immediately recognize that sequence. The Esc ] stuff is usually “system” escape codes, while the Esc [ stuff for various uses including for selecting foreground and background rendering colors.


Semi-related resources:

https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

https://vt100.net

Similar questions

4 replies
Question marked as Top-ranking reply

Jun 8, 2023 8:18 AM in response to cal147

You might try a different terminal emulator.


AFAIK, Apple Terminal.app doesn’t scan for and doesn’t offer clickable hyperlinks in text.


Neither did a DEC VT terminal, nor does DECterm. 🤭


Command-line interfaces don’t generally tend to have GUI mechanisms, either.


What sort of macOS command-line UI are you building?


What’s this code intended to do? Esc ] 8 ; ; — I don’t immediately recognize that sequence. The Esc ] stuff is usually “system” escape codes, while the Esc [ stuff for various uses including for selecting foreground and background rendering colors.


Semi-related resources:

https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

https://vt100.net

Jun 8, 2023 8:50 AM in response to MrHoffman

The program is essentially a bunch of news APIs stitched into a basic set of user inputs -- an attempt to get recent headlines without ever having to deal with website noise/ads/general graphic design chaos. I liked the idea of having a clickable 'READ' hyperlink below the scraped title, just to keep it cleaner than (sometimes absurdly long) URLs


the ]8;; sequence is part of the hyperlink features of some terminal emulators, indicating a hyperlink start -- I initially tested on my VSc terminal where it works as intended, but had little luck finding alternatives or config options for Terminal.app


Worst comes to worst it can be a VSCode-only app, or I can just pass in the links themselves as it looks like (CMD+dblclick) works in Terminal.app with zsh.



Jun 8, 2023 8:57 AM in response to cal147

Applications -> Utilities -> Terminal


URLs and Email Addresses


  • Right-Click with the mouse over a URL, and you will be given the option to open the URL in the default web browser.
    • Command-Double-Click a URL will also open the URL in the default web browser.
    • Either of these can be very useful if you want to quickly follow any URL in a text document.
  • Right-Click with the mouse over an email address, and you will be given the option to compose a new email message in the default email client.


In iTerm2 you can Command-Click on a URL

https://iterm2.com

Jun 8, 2023 9:19 AM in response to cal147

Okay; you’re re-implementing a browser or scraper, or maybe something similar to an RSS reader as a command-line tool, and may well already be familiar with RSS and Atom. (If not, might want to check if the websites offer RSS or Atom feeds, too. Some still do. That’s generally easier than scraping.)


Options for that, from the command line:

https://codezen.org/canto-ng/

https://github.com/akrennmair/newsbeuter

https://lynx.invisible-island.net/


Somebody (presumably Microsoft) “borrowed” that Esc [ 8 ; ; control sequence, eh?


Inferring much, your approach and familiarity and preferences are seemingly tied to Microsoft tools and features, so you’ll probably want to continue along on that path.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Clickable hyperlinks in Terminal.app on zsh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.