The Cookie Machine - Click here to drag window

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

Views: 2,130β€…    Votes:  1β€…    βœ… Solution
Tags: command-line   bash   scripts   notification   zenity  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

Title: Cancel buttons Zenity
ID: /2020/02/20/Cancel-buttons-Zenity
Created: February 20, 2020
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

Assuming that return value is 1 for β€œcancel” and 0 for β€œok” you will want to use:


title=$(zenity --entry --text 'Type what you want your Notification Title to Say!' --title 'Notification')
[[ "$?" != "0" ]] && exit 1
text=$(zenity --entry --text 'Type what you want your Notification body to Say!' --title 'Notification')
[[ "$?" != "0" ]] && exit 1
DISPLAY=:0.0 notify-send "$title" "$text"

You can make a longer traditional check like this:

if [[ "$?" != "0" ]] ; then
    exit 1

however I like the shortcut of:

[[ "$?" != "0" ]] && exit 1

No matter which method you choose the importance is consistency with your programming style so those that follow in your footsteps and maintain your code can think inside your head.

⇧ What does the -tulpn option mean for netstat? Ensure python script isn't run as root  β‡©