On Android, there’s apps that allow you to have a large multitude of running tally-style counters where you simply hit a plus button or whatever and the count goes up by one.
Does anyone happen to be aware of a Manjaro-friendly application where I can keep an unlimited number of different tally counters simultaneously (like all on one hub or scroll list or whatever) and one that will remember its state every time the application is closed, computer restarted, etc?
I have plans of using them similar to the way you might use a habit tracker and keeping up with a large list of things over a long period of time.
Any suggestions or alternatives that seem feasible would be welcomed here. All of my searching has turned up pretty dry.
I’m a pretty nooby Linux user (well, I’m not, but I’m not very programmer savvy).
I was able to copy/paste your text into gedit and then save it as a .sh and run it as a program (I’m actually surprised it was that simple. I’ve never done it before ahaha).
I could make it work and would be willing to make it work if I understood how to select an existing one. I see that your script managed to output a simple text document with the value stored in it. But, after I close the program, I don’t really understand how to recall previously saved tallies if that makes sense.
I’m super impressed at the simplicity and the fact that it saved the values to the side, but I need the ability to run the .sh ideally and all previous tallies open up or something to that effect? Again, I’m a bit flexible here, but that’s where I see my current bottleneck right now.
Thanks for your time and effort! It’s so impressive how quickly you were able to do that and with such little code ahahaha.
#!/usr/bin/env bash
# TallyCat
# Like an alley cat.
# Quick & dirty tally app.
# <3 cscs <3
deftalnam=Count
fultalnam=$(find "$HOME"/.cache/tallycat -type f | sort | awk '{print "FALSE\n"$0}' | zenity --list --radiolist --height 280 --width 420 --separator='\n' --title="TallyCat" --text="Select an existing tally or none to create one" --column="" --column="Files" 2>/dev/null)
[[ "$?" != 0 ]] && exit 1
if [[ -z $fultalnam ]]
then
talnam=$(zenity --forms --title="TallyCat" --text="Create or select a tally" --add-entry="Tally Title")
[[ "$?" != "0" ]] && exit 1
if [[ -z $talnam ]]
then
talnam="$deftalnam"
fi
fultalnam="$HOME/.cache/tallycat/$talnam"
else
talnam=$(basename --multiple "$fultalnam")
fi
COUNTER=0
if [[ -f $fultalnam ]]
then
COUNTER=$(cat "$fultalnam")
fi
rc=1 # OK button return code =0 , all others =1
while [ $rc -eq 1 ]; do
ans=$(zenity --info --title "TallyCat" \
--text "<span>$talnam</span>\n<span><big>$COUNTER</big></span>" \
--icon-name "" \
--ok-label Quit \
--extra-button +1 \
)
rc=$?
if [[ $ans = "+1" ]]
then
(( COUNTER=COUNTER+1 ))
echo "Count is now $COUNTER"
fi
done
mkdir -p "$HOME"/.cache/tallycat
echo "$COUNTER" | tee "$fultalnam"
exit
Sorry - It only allows selecting a single file at a time for now.
Though you can launch it multiple times separately.
Version 0.3
Now with multi-selection
Script here:
TallyCat
#!/usr/bin/env bash
# TallyCat
# A lil like an alley cat.
# Quick & dirty tally app.
# <3 cscs <3
# Define the default tally name
deftalnam=Count
# Start with 0
COUNTER=0
# Function to prompt the user for the tally name
function get_tally_name {
if ! talnam=$(zenity --forms --title="TallyCat" --text="Create or select a tally" --add-entry="Tally Title"); then
exit 1
else
talnam=${talnam:-$deftalnam}
fultalnam="$HOME/.cache/tallycat/$talnam"
fi
}
# Function to display the tally window
function display_tally {
tally=$1
title=$(basename "$tally")
COUNTER=$(cat "$tally")
while true; do
ans=$(zenity --info --title "TallyCat" \
--text "<span>$title</span>\n<span><big>$COUNTER</big></span>" \
--icon-name "" \
--ok-label Quit \
--extra-button +1 \
)
if [[ $ans = "+1" ]]
then
(( COUNTER=COUNTER+1 ))
printf "Count is now %s" "$COUNTER"
else
break
fi
done
printf "%s" "$COUNTER" > "$tally" &
}
# Get the list of tally files using find
mapfile -t tally_files < <(find "$HOME"/.cache/tallycat -type f)
# Prompt the user to select one or more tally files
if ! selected_files=$(printf '%s\n' "${tally_files[@]}" | sort | awk '{print "FALSE\n"$0}' | zenity --list --checklist --height 280 --width 420 --separator='\n' --title="TallyCat" --text="Select one or more tally files" --column="" --column="Files" --multiple 2>/dev/null); then
exit 1
fi
# If no files were selected, prompt the user for a new tally name
if [[ -z $selected_files ]]
then
get_tally_name
mkdir -p "$HOME"/.cache/tallycat
display_tally "$fultalnam"
else
# Display a tally window for each selected file
for file in $selected_files
do
display_tally "$file" &
done
fi
exit
(I probably should have done this with yad, but zenity is more often installed)
Oh, and, the logic is such that
First you are presented with a file selection
Selecting one opens that tally, if none then you are presented with the input prompt
Inputting an existing Tally into the prompt will open that tally, if no file matches the tally name it will create and start a new one, and if no input is provided it will use tally “Count”.
Also note that because these are simply text files with the count in them … you can manually create, delete, or edit the tallies.
Ex: If you want to tally “Red_Cars” and you know you have already counted 53 of them … simply create the file at the TallyCat location (~/.cache/tallycat/) with 53 as the content.
EDIT … I did a version 0.3 with multi-select now, but didnt want to make a new post. See above.
WOW! Ahahaha. This is awesome! I know it’s only some “small upgrades,” but the QoL impact on this is huge. I could def work with something like this!
I really appreciate the simplicity of the user interface, I LOVE that you added the tally count to the GUI box instead of only seeing it in the terminal, and now I’ve discovered that the file location for each of these is saved into the .cache folder in my home directory so that I can go delete ones if I no longer need them.
I can more than work with a single file for now. It’s really a minor point. The fact that it’s visually intuitive I feel is the most important part since it’s something I plan on quickly opening and closing a couple times a day just to add a tally to something over months/years. So, having something that can be quickly done with a few mouse clicks ensures I’ll use it more consistently and that it won’t interfere with my work flow.
Ah, lol. I see you added a version 0.3 that allows for multiple files. I just tried it out. Unfortunately when I click two boxes and hit “okay,” it just closes and I see nothing. I did double check and I do have zenity installed (from the official repository), so I don’t believe that’s the issue. If I’m doing something wrong, feel free to let me know.
Regardless, this is awesome! I really appreciate your time/effort!
Edit: Actually, with V0.3 in general, any time I select any of them, it seems to crash/terminate. I did not have this issue with your V0.2, though.
Tis good to have left the trail of work then.
But sad its not working for you… results here are good.
(except that … the window insists on closing and then re-opening in the center of the screen … but could be my desktop setting … in any case zenity is more meant for info boxes and is somewhat of an old curmudgeon)
It appears clean for shellcheck.
I suppose I might suggest running it from the terminal (though I did just test launching it graphically too).
Ex;
Mark executable:
chmod +x TallyCat
Run:
bash TallyCat
Commands above assume TallyCat is in the same directory … otherwise use full path.
And … just to list them … it uses: zenity, printf, mapfile, sort, awk, and mkdir.
Looking at it … mapfile is the difference … along with the whole array thing.
Which shouldnt be an issue … but … it appears maybe it is?
Maybe I’m a bit of a dense block of wood, but I wasn’t able to troubleshoot my way through version 0.3 on my end. I’m still just having it crash out after selecting multiple options. I can more than make version 0.2 work if need be, though, so I appreciate you being iterative and sharing it as well!