Given that nyxt has already been started,
can one open a new nyxt browser window from the command line, displaying an URL?
If I just invoke
nyxt https://github.com
then that URL is displayed in the already existing nyxt browser window. This is of course expected.
With an already running google-chrome one can open a new browser window with, for example:
google-chrome --new-window https://github.com
Why do I want to do this? When using a window manager, such as i3 or sway, it can be convenient to open a new browser window, and to do that in a specific position on the display. With other browsers this can be achieved by invoking a command in the window manager that executes a script to create the new browser window. The window manager controls where the new window will be displayed.
@johan_widen what you’re trying to achieve is not to start another Nyxt process, but to create a new window. For that we have the command make-window. Does that help? Thanks.
I also tried this:
$ nyxt -r -e ‘(make-window (make-buffer “https://github.com”))’
If I just submit the inner sexpr (make-buffer) that one succeeds and creates the buffer in the existing nyxt window. But if I try the whole sexpr, I get the error:
Could not extract URLs from “(make-window (make-buffer "https://github.com"))”.
@johan_widen if you want to programmatically create a new window and load a specific URL you need to issue (make-window (make-buffer :url "https://en.wikipedia.org/wiki/Tomato")).
For reference, for those that want to control a running Nyxt process from the the command line:
Add the snippet below to your config file;
(define-configuration browser
(
;; Whether code sent to the socket gets executed. You must understand the
;; risks before enabling this: a privileged user with access to your system
;; can then take control of the browser and execute arbitrary code under your
;; user profile.
(remote-execution-p t)))
Start Nyxt;
To communicate with the Nyxt process: (1) issue nyxt --remote which behaves as a Nyxt interpreter or (2) send a single sexp for evaluation, for instance nyxt --remote --eval '(echo "Hello Nyxt!")'.
Thank you so much! I was successful with your recipe.
I used the following shell command (after having added the define-configuration snippet to nyxt config):
nyxt -r -e ‘(make-window (make-buffer :url “Tomato - Wikipedia”))’ -q
The -q is so that the command terminates, instead of waiting for input from stdin.
Good @johan_widen! I see that you were able to figure out the --quit flag by yourself. I argued, in issue #3047, that --quit should be the default when using both --remote and one of --load or --eval.
What do you think? We’re interested in your opinion!
Jumping in here, I need to be able to do this as well, but it isn’t working for me:
I downloaded and compiled Nyxt tonight (v 4.0). As a side point, holy moly is this a lot faster than 3.x. I do expect bugs so no worries.
I have added the following to my config.lisp:
;; from url: How to open a new browser window from command line? - #4 by johan_widen
;; allow remote control over nyxt
(define-configuration browser
(
;; Whether code sent to the socket gets executed. You must understand the
;; risks before enabling this: a privileged user with access to your system
;; can then take control of the browser and execute arbitrary code under your
;; user profile.
(remote-execution-p t)))
The error message returned:
[03:39:59] Probing remote instance listening to /run/user/1001/nyxt/nyxt.socket.
[03:39:59] No instance running.
QUESTION: What I missing here? Any suggestions are welcome, I don’t see anything obvious.
GOAL: I need to create some scripts to open up multiple windows of Nyxt, log in to interfaces and have it click on default items. The first step is to get Nyxt to just open up a window though.
I had an error in my config + I had a shortcut that was starting up Nyxt with --no-socket for some reason. And wow, 3.x was much faster than 2.x, but 4.x is a bit of a game changer. I was not expecing this. Going to do a bit more testing.
This works now. Great! Thanks for the heads up.
Next question: The warning about enabling connection to a socket is interesting. Would the proper way to mitigate any security issues be opening up Nyxt as separate processes?