How to Open a Data Scheme URI from a Terminal in a Default Browser on a Mac

Asked 2 years ago, Updated 2 years ago, 42 views

When opening a URI from a Mac terminal in a default browser, you can use the open command to:

$open http://example.com/

However, you cannot do the same with URIs that begin with data: .
I think I'm looking for it locally as a file.

$open data:text/plain; base64,SGVsbG8sIFdvcmxkIQ==
The file/Users/yuya/src/github.com/yuya-takeyama/qrcat/data:text/plain does not exist.
zsh:command not found:base64,SGVsbG8sIFdvcmxkIQ==

Is there any way to do this well?
I would like to open it in the default browser without specifying a specific browser.

macos

2022-09-30 19:24

1 Answers

I found a similar question in the English version of SO.

osx-Open an.html file with default browser using Bash on Mac

This section describes how to use the third-party command DefaultApplication.If you use this, you can write like this (although I don't have a Mac on hand, so I can't verify it).

open-a"$(/usr/local/bin/DefaultApplication-url'http:')""data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="

There seems to be a way to get the default browser using Perl or AppleScript.

osx-Discover default browser programmatically on Mac-Super User


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.