If you have checked the option Ask each time for the Executable Text File in the Nautilus Preferences, then you will have two options Run in Terminal
and Run
, when you (double) cluck on an executable by the mouse:
You need to choice Run
to achieve what you want. This is also the default behavior if you have set Run executable text files when they are opened in Nautilus Preferences.
These two options Run in Terminal
and Run
have different behavior, but unfortunately I didn't found any additional documentation. Probably the first one creates a temporal environment that is annihilated when the terminal is closed. We can prove that by adding exec sh
at the bottom of your script:
#!/bin/sh --
oathtool -b --totp XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | xclip -sel clip
echo "OTP Copied!"
sleep 2
exec sh
The command exec sh
will replace the current shell (of your script) by a new sh
shell, thus the terminal window will be kept open and your clipboard will be active until you are close the terminal window. Another option is to extend the sleep
time, then your clipboard will be active while the terminal window sleeps.
If you are using the Run
option or custom shortcut I would suggest you to modify your script in this way:
#!/bin/sh --
oathtool -b --totp XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | xclip -sel clip \
&& notify-send "OTP Copied!"
Thus notify-send
will send you a notification within the GUI environment only when the previous command returns true, which is the meaning of &&
.
I've tested the described above in Ubuntu 16.04 and 19.04, there is no difference - the same behavior and the proposed solutions are working in both OS.
oathtool
andxclip
are located in/usr/bin/
.