How to programmatically open Pluto in a VS Code new tab from the Julia Terminal?

I am trying to capture the Pluto URL programmatically ’ pluto_url = some code’ without auto-open and afterwards opening it inside VS Code. Is it possible?

using Pluto
# Start Pluto 
@async Pluto.run(; autoopen=false) 

# Capture the Pluto URL ensuring the secret token is included
pluto_url = some code

# Pluto uses VS Code’s internal browser in a new tab
@async run(`code --reuse-window "$pluto_url"`)
1 Like

Run Pluto the Long Way

julia> using Pluto

julia> options = Pluto.Configuration.from_flat_kwargs(; launch_browser=false);

julia> session = Pluto.ServerSession(; options, secret="password");

julia> pluto_url = Pluto.pretty_address(session, options.server.host, options.server.port_hint)
"http://localhost:1234/?secret=password"

julia> t = @async Pluto.run(session);

julia> @async run(`code --reuse-window "$pluto_url"`)

Set the password to whatever you want.

1 Like

Thank you very much for your help. When I run your script (on a Mac) it opens VS Code with a tab named ?secret=password but no Pluto running.


I wonder if possibly the t in t = @async Pluto.run(session); should be used somewhere afterwards?

Regarding the ?secret=password tab

I don’t know how to open a web page in VS Code from the command line. I don’t normally use VS Code, so I was trusting your run expression worked. I looked into it a bit, but I couldn’t find anything. What does:

code https://www.google.com/

do for you? I get an empty tab and not the SimpleBrowser tab I was hoping for.

Regarding t = @async Pluto.run(session)

If you’re running this as a script outside of the REPL, put a wait(t) at the end. Otherwise, the script will exit and the Pluto server will stop.

While VSCode can open urls using the integrated SimpleBrowser extension, it does not seem like there is an easy/official way of executing commands provided by VSCode extension directly using the VSCode cli from the command line.
See for example these links from stackoverflow: [1], [2]

1 Like