I want to echo the currently selected list when i press a button, but all it does is run the function i assign to the button. I want it to detect if a list was selected, if not show another yad window saying "Please select a Task/Reminder to use this button!", but if something was selected display a yad window saying "You selected: List name List date" Thanks.
#!/bin/bash
DIRECTORY="$(readlink -f "$(dirname "$(dirname "$0")")")"
AppName="$(cat $DIRECTORY/data/info/appname.inf)"
Used="$(cat $DIRECTORY/data/info/opd)"
#load functions
source "${DIRECTORY}/scripts/functions" || error "failed to source ${DIRECTORY}/scripts/functions"
#Display MainMenu if program has been used before.
if [ $Used == "True" ]; then
#Display Tasks/Reminders if there are any
if [ -d "$DIRECTORY/Tasks" ]; then
while IFS='|' read -r Name Date _; do
if [[ $Name || $Date ]]; then
items+=( "$Name" "$Date" )
else
items+=( "None" "None" )
fi
done < <(sort -t'|' -k2 $DIRECTORY/Tasks/Tasks.txt)
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='300' --text-align="center" --text="Welcome to $AppName! \nWhat would you like to do?" --button="Add new Task/Reminder"!"${DIRECTORY}/icons/install.png"!'Create a new Task/Reminder':2 --button="Delete Task/Reminder"!"${DIRECTORY}/icons/uninstall.png"!'Delete Task/Reminder':3 --list --column=Task/Reminder "${items[0]}" --column=Date "${items[1]}"
else
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='100' --text-align="center" --text="Welcome to $AppName! \nWhat would you like to do?" --button="Add new Task/Reminder"!"${DIRECTORY}/icons/install.png"!'Create a new Task/Reminder':2
fi
else #Display StartupMenu.
yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='300' --text-align="center" --text="Thanks for instaling $AppName! \nClick next to learn how to use $AppName." --window-icon="${DIRECTORY}/icons/logo.png" --button=Cancel!"${DIRECTORY}/icons/exit.png"!'Exit':0 --button='Next'!"${DIRECTORY}/icons/forward.png"!'Continue.':1
fi
button=$? #get exit code to determine which button was pressed.
if [ $button -eq 0 ];then
echo "True" > $DIRECTORY/data/info/opd
elif [ $button -eq 1 ];then
bash "$DIRECTORY/scripts/firstrun/learn"
elif [ $button -eq 2 ];then
nameofnew="$(yad --entry --window-icon="${DIRECTORY}/icons/logo.png" --separator='\n' --title="Create a new Task/Reminder" --center --text-align="center" --entry-label="Name of new Task/Reminder:")"
selecteddate="$(yad --calendar --window-icon="${DIRECTORY}/icons/logo.png" --title="Select a date" --height="200" --width="400")"
yad --separator='\n' --window-icon="${DIRECTORY}/icons/logo.png" --title="Is this correct?" --center --width='300' --height='300' --text-align="center" --text="Is this correct? \nName of Task/Reminder: '$nameofnew'\nSelected date for new Task/Reminder: '$selecteddate'" --button="No"!"${DIRECTORY}/icons/exit.png"!'No':2 --button='Yes'!"${DIRECTORY}/icons/check.png"!'yes':3
elif [ $button -eq 3 ];then
if [ -d "$DIRECTORY/Tasks" ]; then
yad
else
g
fi
elif [ $button -eq 252 ];then
exit 0
else
error "Unkown button input recived: $button"
fi
All I had to do was store the yad window as a variable; then, I could get the selected list.
option="$(yad --separator='\n' --title="$AppName" --window-icon="${DIRECTORY}/icons/logo.png" --center --width='300' --height='300' --text-align="center" --text="Welcome to $AppName! \nWhat would you like to do?" --button="Add new Task/Reminder"!"${DIRECTORY}/icons/install.png"!'Create a new Task/Reminder':2 --button="Delete Task/Reminder"!"${DIRECTORY}/icons/uninstall.png"!'Delete Task/Reminder':3 --list --column=Task/Reminder "${items[0]}" --column=Date "${items[1]}")"
echo $option
if [ "$option" -eq "" ]; then
yad --title="Error" --text="You didn't select a Task/Reminder! Please go back and try again"
else
# Do something with the selected items.
fi