Sunday, May 12, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1398  / 2 Years ago, tue, february 8, 2022, 8:50:14

so a pretty straight forward question , on zenity theres is 2 buttons on each page , ok and cancel . with my script i manage to assign the zenity code to a variable where i can pick a date for my calendar. I would like to use the cancel button for my agenda , so i renamed it but i don't know how to make it work! thanks


#!/bin/bash
calendarinput=$(zenity --calendar
--title "Scheduler"
--text "Pick a date"
--ok-label "Done" --cancel-label "Agenda"
--date-format "%A %d/%m/%y")

agenda+="$calendarinput"
unset calendarinput
calendarinput="Done"

if [ "$calendarinput"="Done" ];then
remind=$(zenity --entry)
agenda+="$remind
"
fi

zenity --info
--text "$agenda"

This is a only 1 function of my script.There is another list menu before this one.


More From » command-line

 Answers
3

You can find the return code from the buttons in the special parameter $?, which holds the exit code from the last executed command. It can either be 0, 1, or 5, depending on whether the user pressed OK, Cancel, or timeout.


#!/bin/bash

calendarinput=$(zenity --calendar
--title "Scheduler"
--text "Pick a date"
--ok-label "Done" --cancel-label "Agenda"
--date-format "%A %d/%m/%y")

ret=$?

if ((ret==0)); then
echo "Done"
else
echo "Agenda"
fi

The expressions in an if-statement need to be separated with space:


if [ "$calendarinput" = "Done" ]; then

(It will also always evaluate as true, which makes it somewhat unnecessary).


[#2052] Tuesday, February 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eatack

Total Points: 245
Total Questions: 120
Total Answers: 113

Location: Estonia
Member since Wed, Jun 8, 2022
2 Years ago
eatack questions
Sun, Mar 6, 22, 20:44, 2 Years ago
Sat, May 20, 23, 13:30, 1 Year ago
Fri, Apr 28, 23, 06:04, 1 Year ago
;