The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,107     Votes:  3 
Tags: scripts   desktop-environments   virtual-console  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

URL: https://askubuntu.com/q/1039023
Title: How to have script detect if terminal emulator is running in a desktop session or not?
ID: /2018/05/22/How-to-have-script-detect-if-terminal-emulator-is-running-in-a-desktop-session-or-not_
Created: May 22, 2018    Edited:  May 22, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


This is what I’ve been using:

# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
    notify-send --urgency=critical "$0 cannot be run from GUI without TERM environment variable."
    exit 1
fi

The reason for this code was this question: Desktop shortcut to Bash script crashes and burns

You can modify it to look like this:

# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
    nano ...
else
    gedit ...
fi
⇧ How do you manage journald log history on ubuntu core 16 how to do I force-yes on fsck  â‡©