How to launch interactive GLMakie script from terminal

I have a script for an interactive plot made with GLMakie. The script works on REPL (launched via VS Code).
However, I would like to launch the script from terminal directly. Thus, I wrote a script in bash to launch the julia file. The file is launched, but the GLMakie is not displayed and then the julia script crashes.
In this example, this is the julia file (testButton.jl):

using GLMakie
println("Starting Julia script")
xs = range(0, 10, length = 30)
ys = 0.5 .* sin.(xs)
fig = Figure()
ax = Axis(fig[1,1], title = "Example", ylabel = "Y", xlabel = "X")
sc = scatter
lines!(ax, xs, ys, linewidth = 5, color =:midnightblue)
fig[2,1] = buttongrid = GridLayout(tellwidth = false)
buttons = buttongrid[1,1] = [
    Button(fig, label = "Save Figure", fontsize = 18)
]
on(buttons[1].clicks) do click
    save("Test.png", fig)
end

and this is the launcher (ButtonLauncher):

#!/usr/bin/env bash

printf "Launching test button\n"
exec julia testButton.jl
printf "Task completed\n"
exit 0

When I launch the application, I get:

$ ./ButtonLauncher 
Launching test button
Starting Julia script
$ 

This means the script is launched (first printf statement) but the application does not reach the end (second printf statement). To note that I launched the Julia file with exec to remain within the bash environment.
How can I launch an interactive plot from terminal?
Thank you

Note that exec does not start a new process for Julia alongside the shell process, it replaces the shell process. This means that it should be expected that whatever remains in the shell script will never be executed.


I think what happens here is that your Julia script correctly starts but immediately stops because it does not have anything to wait for. As a first step to test this hypothesis, I think one thing you can try using the -i command-line switch: this switches Julia to “interactive” mode. With this a Julia REPL will open and so should your GLMakie window. When you close the Julia REPL (e.g. with ctrl+d) the GLMakie window should be killed too.

You launcher script would then look like:

#!/usr/bin/env bash

printf "Launching test button\n"
julia -i testButton.jl
printf "Task completed\n"
exit 0

You can also try the suggestion here to call wait

2 Likes