You are not logged in.

#1 2023-02-19 15:24:08

hat@ke73
Member
Registered: 2023-02-19
Posts: 4

[Solved] How to run the script through nautilus with the console?

Here's the thing, I'm learning Python (but I think my problem extends to any interpreted language). And with that, I already understood that the first line should be:

#!/usr/bin/env python
print('...')
x=int(input())

With that, when I run my program through the console it works perfectly.

However, I would like to be able to run it through the graphical interface

(1) Right click > run as program

Searching the internet, I saw that I would need to adapt the first line to:

#!/usr/bin/env -S python './test3.py'
print('...')
x=int(input())

However, this only works when I install gnome-terminal.

Therefore, I would like to know if anyone has any idea what I should do to achieve the desired effect (1) using only the console that comes by default in Arch, without having to install gnome-terminal.

*Besides being a beginner in programming, I am also a beginner in English, so I used google translator, but I hope my problem is clear.

Last edited by hat@ke73 (2023-02-19 17:06:14)

Offline

#2 2023-02-19 15:36:04

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 71,684

Re: [Solved] How to run the script through nautilus with the console?

The altered shebang is nonsense and running scripts has principally nothing to do w/ terminal emulators.
The problem is the desktop service you're using to trigger the script from the rmb menu.
It'll have a "Terminal=true" line and that uses the default terminal of your environment (arch does not have something like a default terminal emulator or anything "default" and there's no xdg spec for this either)

=> What's your desktop environment and from which process do you invoke the rmb menu?

Online

#3 2023-02-19 15:47:41

hat@ke73
Member
Registered: 2023-02-19
Posts: 4

Re: [Solved] How to run the script through nautilus with the console?

Here are some of the outputs of neofetch:

OS: Arch Linux x86_64
Kernel: 6.1.12-arch1-1
shell: bash 5.1.16
FROM: GNOME 43.3
WM: Mutter
WM Theme: Adwaita
Theme: Adwaita-dark [GTK2/3]
Icons: Adwaita [GTK2/3]
terminal: kgx

About the process is literally: right click and choose run as a program.

Offline

#4 2023-02-19 16:04:13

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 71,684

Re: [Solved] How to run the script through nautilus with the console?

No, what program do you use where you right-click.
I guess it's nautilus and you want to use gnome-console as default TE.

From what I can find, gnome (now) hardcodes this to gnome-terminal and you'll have to symlink /usr/bin/gnome-terminal to /usr/bin/kgx which, as everything gnome, is murky as hell.
https://gitlab.gnome.org/GNOME/glib/-/issues/338

Apparently they intend to add an xdg-terminal-exec to glib (which is batshit, because gnome doesn't control xdg, but hey…), but that will require glib2 2.76 - so later this year.

Online

#5 2023-02-19 16:08:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,439
Website

Re: [Solved] How to run the script through nautilus with the console?

hat@ke73 wrote:

About the process is literally: right click and choose run as a program.

Right click in / on what?  On an icon on a desktop?  If so the desktop manager would be the relevant process.  Or in a file manager?  In which case knowing which file manager would be important.

(edit: cross posted w/ the above post)

Last edited by Trilby (2023-02-19 16:08:57)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2023-02-19 16:55:22

hat@ke73
Member
Registered: 2023-02-19
Posts: 4

Re: [Solved] How to run the script through nautilus with the console?

seth wrote:

No, what program do you use where you right-click.
I guess it's nautilus and you want to use gnome-console as default TE.

From what I can find, gnome (now) hardcodes this to gnome-terminal and you'll have to symlink /usr/bin/gnome-terminal to /usr/bin/kgx which, as everything gnome, is murky as hell.
https://gitlab.gnome.org/GNOME/glib/-/issues/338

Apparently they intend to add an xdg-terminal-exec to glib (which is batshit, because gnome doesn't control xdg, but hey…), but that will require glib2 2.76 - so later this year.

Worked perfectly! That's exactly what I wanted. Thank you very much "seth"!!

Now, I'm going to do some research on how to make the console close automatically when the program finishes executing. big_smile big_smile big_smile

Last edited by hat@ke73 (2023-02-19 16:56:16)

Offline

#7 2023-02-19 16:58:39

hat@ke73
Member
Registered: 2023-02-19
Posts: 4

Re: [Solved] How to run the script through nautilus with the console?

Trilby wrote:
hat@ke73 wrote:

About the process is literally: right click and choose run as a program.

Right click in / on what?  On an icon on a desktop?  If so the desktop manager would be the relevant process.  Or in a file manager?  In which case knowing which file manager would be important.

(edit: cross posted w/ the above post)

In the case I click with the right button through the nautilus file manager.

Offline

Board footer

Powered by FluxBB