You are not logged in.

#1 2018-08-09 15:40:44

Maniaxx
Member
Registered: 2014-05-14
Posts: 732

[SOLVED]XFCE - Execute send-to-desktop shell script in terminal

I have several custom shell scripts linked on my desktop to quickly do some stuff like start smb shares, turn off 2nd hdd, switch display (tv/monitor), start libvirt service, change mouse buttons, pulseaudio-on and such. My current workflow is to create the shell script itself (in my home folder) and an XFCE/Thunar desktop "starter" (link on the desktop) that actually points to that script (with Starter option "start in terminal" so i can see the output of the script).

This works great but maybe its possible to optimize it some more / omit the last step (creating the "starter"). There is another way to place a shell script on the desktop by using Thunars "send to desktop" context option (actually just a soft link). This does work as well but there is no terminal window opening. Just the script running in background. No visual feedback.

#!/bin/sh
echo blahblah

Now i'm wondering if its possible to start the terminal first and pass the subsequent commands somehow (pseudo example - doesn't work).

#!/bin/sh
exec gnome-terminal
echo blahblah
echo blublub

I want to keep the code/script as original as possible. Nothing with line breaks like this (not sure if this even works):

#!/bin/sh
exec gnome-terminal -e "\
echo blahblah; \
echo blublub; \
echo bloblob"

Any idea how to do this?
Maybe its possible to start a terminal (in background) to a dedicated tty and connect input/output to that terminal? The script is connected to tty1 when invoked by the send-to-desktop link.

Last edited by Maniaxx (2018-08-10 17:06:22)


sys2064

Offline

#2 2018-08-09 22:19:39

toz
Member
Registered: 2011-10-28
Posts: 494

Re: [SOLVED]XFCE - Execute send-to-desktop shell script in terminal

You can use a Thunar sendto desktop file such as this (save as ~/.local/share/Thunar/sendto/thunar-sendto-terminal.desktop):

[Desktop Entry]
Type=Application
Version=1.0
Name=Terminal 
Icon=xfce4-terminal
TryExec=xfce4-terminal
Exec=xfce4-terminal -H -e  %F

Then right-click on the file and select "Terminal" in the sendto menu. This will open a terminal window and execute the file you clicked on.

Offline

#3 2018-08-09 23:45:09

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

Re: [SOLVED]XFCE - Execute send-to-desktop shell script in terminal

Just start every script with a line like this:

#!/bin/sh
[ -t 1 ] || exec gnome-terminal -e $0

# ... rest of the script here

So if the script is started without being connected to a terminal, it will instead exec gnome-terminal and start itself in that terminal.

This is assuming gnome-terminal uses the -e flag like several other terminals, if not, replace that with the appropriate flag.

You also should not need to "send to desktop", just create the scripts on the desktop in the first place.

Last edited by Trilby (2018-08-10 04:02:52)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2018-08-10 16:29:42

Maniaxx
Member
Registered: 2014-05-14
Posts: 732

Re: [SOLVED]XFCE - Execute send-to-desktop shell script in terminal

toz wrote:

You can use a Thunar sendto desktop file such as this

Good for 'Run in Terminal' context menu entry. Thanks.

Trilby wrote:

start every script with a line like this:

#!/bin/sh
[ -t 1 ] || exec gnome-terminal -e $0
Trilby wrote:

if the script is started without being connected to a terminal

It is connected to tty thus a slight change. The idea is nicely working. Thanks.

[ $(tty|grep pts) ] || exec gnome-terminal -e $0

sys2064

Offline

#5 2018-08-10 17:46:02

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

Re: [SOLVED]XFCE - Execute send-to-desktop shell script in terminal

I'm curious did my version not work?  It's running under a logged in tty session, but the script itself should not have it's stdout connected to a tty when run from a desktop file.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2018-08-10 18:54:43

Maniaxx
Member
Registered: 2014-05-14
Posts: 732

Re: [SOLVED]XFCE - Execute send-to-desktop shell script in terminal

No, it didn't work. The script is connected to tty (looked up with 'ps aux') and thus [ -t 1 ] is true.
My desktop script is a softlink to a *.sh file in my home folder.

Last edited by Maniaxx (2018-08-10 18:57:17)


sys2064

Offline

Board footer

Powered by FluxBB