0

I'm working on a desktop app that uses a terminal popup to show the user what processes it is doing such as git cloning, installing packages, etc. The problem is that my team and I have resorted to installing and using Xterm for all users which looks out-of-place most of the time. I've been trying to find a reliable method to simply grab the system's default terminal emulator and launch it.

I've been told from someone to run os.system('basename "/"$(ps -f -p $(cat /proc/$(echo $$)/stat | cut -d \ -f 4) | tail -1 | sed \'s/^.* //\')') which will use bash to detect the terminal. Unfortunately this seems to only read the name of the file the command was executed from. It prints python from a Python shell, test.py from a script, and konsole from konsole. I tried using the command in a bash script and calling that but it only printed the name of the file it was in.

I've also been told to use os.system('echo $TERM') but it only outputs xterm-256color no matter what.

I tried pstree -sA $$ | head -n1 | awk -F "---" '{ print $(NF-1) }' and calling directly through Python and through bash script through Python and still no luck. Just exporting python.

Does anyone have a solution to check the default terminal? This must be able to run in a Python script to be stored as a variable. I simply need a native terminal emulator.

Edit: I'm running Arch Linux with the KDE desktop environment. This is being designed to run across any and every desktop environment.

  • Possible duplicate of [Launch default terminal emulator by command](https://unix.stackexchange.com/questions/481142/launch-default-terminal-emulator-by-command) – Panki Oct 31 '19 at 11:00
  • 1
    Possible duplicate of [How to launch an application with default "terminal emulator" on Ubuntu?](https://unix.stackexchange.com/questions/32547/how-to-launch-an-application-with-default-terminal-emulator-on-ubuntu) – roaima Nov 02 '19 at 23:23
  • @roaima Not a duplicate because that command doesn't exist in Arch Linux. – Caden Mitchell Nov 08 '19 at 19:45
  • @Panki those don't work for me from a Python or C shell and that command only reports "gnome-terminal" on KDE even though it is actually Konsole and Gnome Terminal is not installed. – Caden Mitchell Nov 08 '19 at 19:46
  • @roaima Sorry about that! I'll add that! – Caden Mitchell Nov 10 '19 at 22:51
  • 1
    I've been thinking... If I've got XFCE and Gnome installed, and one user prefers the first but the second user prefers the other, what is "_the system's default terminal emulator_"? Would it be more correct to look for the _user's_ default terminal emulator? – roaima Nov 10 '19 at 23:10
  • I think you have a point @roaima! I honestly am at a loss for this one, though. I don't know of any program/library that can read the user pref for any given desktop environment unfortunately. :( – Caden Mitchell Nov 11 '19 at 01:18
  • Why not make the setting (choice of terminal emulator) configurable by the user? Default to, say, `xterm` – roaima Nov 11 '19 at 07:38
  • @roaima Well, I would but the problem is that if I pre-install Xterm, the user has to deal with having an extra terminal that is not even native and looks bad. Installing Konsole or Gnome Terminal would also not work because they aren't native on all desktops. – Caden Mitchell Nov 12 '19 at 02:50

0 Answers0