Page 37 of 42

Posted: Thu 19 Sep 2019, 11:53
by stemsee

Code: Select all

export z

Posted: Thu 19 Sep 2019, 12:06
by achim
@ Stemsee,

where exactly should I enter the code?

Posted: Thu 19 Sep 2019, 12:22
by achim
with "export z" I already tested yesterday, unfortunately did not work, strange

Posted: Thu 19 Sep 2019, 12:49
by stemsee
fredx181 wrote:Hi achim, probably there are different ways, but what I would do is pipe to a yad --text-info dialog, like this:

Code: Select all

cd $CAMERA/
(
z=0
for f in *.jpg; do name=`echo "${f%.*}"`; echo "Kopiervorgang des Bildes "$f" läuft..."
   rsync -t $CAMERA/"$f" $ZIEL/$DATE/;
   z=$(($z+1)); export z;

echo "Der Kopiervorgang des Bildes"

echo "$f"

echo "wird als laufende Nr. $z durchgeführt..."
echo "$z Bilder kopiert"
done
) | yad --text="Kopiervorgang des Bildes" --width=600 --height 200 --fixed --window-icon="$HOME/.icons/Movies-icon24.png" --text-info --wrap --tail \
--title="Verlaufskontrolle" --text-align=center --no-buttons
because you want the last value assigned to z, not the first. So z gets updated on each iteration of the loop. You could write it to a file in /tmp ((NOTE BENE not '[' but '(( ))'

Code: Select all

z=$((z + 1)); echo "z=$z" >/tmp/z

Posted: Thu 19 Sep 2019, 14:52
by achim
... You could write it to a file in /tmp ...
I would like to choose this option. Just how do I call the variable later - z=$(/tmp/z) ?

Posted: Thu 19 Sep 2019, 14:58
by stemsee

Code: Select all

. /tmp/z
this imports the variable and its value into the script/command that calls it.

please note that the file in /tmp could be called anything .... /tmp/MYNAME

Code: Select all

. /tmp/MYNAME
echo "$z"
12
you can check the contents with

Code: Select all

cat /tmp/MYNAME
z=12

Posted: Thu 19 Sep 2019, 15:16
by misko_2083
stemsee wrote:out of interest

non pipe version. type on commandline and hit enter to send.

How to make it send as it is being typed without newlines until return is hit??

Code: Select all

while true; do read ound; echo "$ound"; done | yad --text-info --listen --width=200 --height=200

Code: Select all

buffer="";  while true; do IFS='' read -N 1 ound;  [[ "${buffer}" == *$'\n'* ]] && buffer=""; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200
even better with --tail option

Code: Select all

buffer="";  while true; do IFS='' read -N 1 ound; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200 --tail
stemsee wrote: How to make it send as it is being typed without newlines until return is hit??
^It was hard to decode what the writer wanted to say. :D

Posted: Thu 19 Sep 2019, 15:48
by achim
Hello stemsee,

now the script works! thanks again

Posted: Sat 21 Sep 2019, 22:32
by stemsee
misko_2083 wrote:
stemsee wrote:out of interest

non pipe version. type on commandline and hit enter to send.

How to make it send as it is being typed without newlines until return is hit??

Code: Select all

while true; do read ound; echo "$ound"; done | yad --text-info --listen --width=200 --height=200

Code: Select all

buffer="";  while true; do IFS='' read -N 1 ound;  [[ "${buffer}" == *$'\n'* ]] && buffer=""; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200
even better with --tail option

Code: Select all

buffer="";  while true; do IFS='' read -N 1 ound; buffer="${buffer}${ound}"; echo -e "\f"; echo "${buffer}"; done | yad --text-info --listen --width=200 --height=200 --tail
stemsee wrote: How to make it send as it is being typed without newlines until return is hit??
^It was hard to decode what the writer wanted to say. :D
I see the trick! refresh after each character while remembering all previous typing.

backspace is not possible!?

stemsee

Posted: Sun 22 Sep 2019, 08:17
by MochiMoppel
stemsee wrote:backspace is not possible!?
Try this:

Code: Select all

while true ;do
	IFS='' read -rsN 1 ound
	if [[ $ound == $'\x7f' ]] ;then
		buffer=${buffer%?}
		echo -ne "\b" >&2
	else
		buffer=$buffer$ound
		echo -n "$ound" >&2
	fi
	echo -e "\f"
	echo "$buffer"
done | yad --text-info --width=200 --height=200 --tail
Added: read options -r (to allow direct entry of backslash character) and -s (to prevent ugly terminal output when entering backspace)
Removed: yad option --listen

@misko_2083: Clever approach :lol:

Posted: Sun 22 Sep 2019, 12:15
by stemsee
@MochiMoppel
Amazingly good .... even does away with refresh flickers! .It could have been you who hacked Neo's cli?? :D

Posted: Mon 23 Sep 2019, 05:53
by step
@MochiMoppel, WOW! Thanks.

Posted: Mon 23 Sep 2019, 11:56
by misko_2083
MochiMoppel wrote: @misko_2083: Clever approach :lol:
It depends.
A few sentences and it's fine.
More new lines/chars - more refresh glitch.
Milions of characters in a variable and you run out of memory. :!:
Though, it's very unlikely that stemsee will use this method to write a book. :lol:

Posted: Mon 23 Sep 2019, 13:08
by misko_2083
Bit off topic:
Wanted to have something siimilar to the MATE desktop shutdown timer, only for the Xfce desktop.
It would run xfce4-session-logout -h after the timeout or a shutdown button click.
Yad does not let me change the text label so... resorted to c and gtk3.

Save next as timer.c

Code: Select all

#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

/* Shutdown timer */

static      gboolean continue_timer = FALSE;
static      gboolean start_timer = TRUE;
static      int sec_expired = 30;

/* Shutdown command here */
static      gchar      *command[] = { "xfce4-session-logout -h",NULL };
GError     *error = NULL;

static void
_quit_cb (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    gtk_main_quit();
    return;
}

static void
shutdown (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    g_spawn_command_line_async(*command, &error);
    if (error != NULL) {
        g_warning("unable to launch: %s", error->message);
        }
    gtk_main_quit();
}

static gboolean
_label_update(gpointer data)
{
    GtkLabel *label = (GtkLabel*)data;
    char buf[256];
    memset(&buf, 0x0, 256);
    snprintf(buf, 255, "Turning off computer in  %d seconds.", --sec_expired);
    if (sec_expired == 0)
        {
        g_spawn_command_line_async(*command, &error);
        if (error != NULL) {
            g_warning("unable to launch: %s", error->message);
            }
        gtk_main_quit();
        }
    gtk_label_set_label(label, buf);
    return continue_timer;
}


int main(void)
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *boxl;
    GtkWidget *shutdown_button;
    GtkWidget *cancel_button;
    GtkWidget *label;
    GtkWidget *question;

    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window, 250, 120);
    gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
    gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
    gtk_window_stick (GTK_WINDOW (window));
    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
    gtk_window_set_title (GTK_WINDOW (window), "Shutdown");
    g_signal_connect (G_OBJECT (window), "destroy", 
                    G_CALLBACK (gtk_main_quit),
                    NULL);
    box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    boxl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);

    gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
    gtk_container_add(GTK_CONTAINER(window),boxl);

    question = gtk_label_new("\nAre you sure you want to shutdown?");
    label = gtk_label_new("Turning off computer in  30 seconds.");

    shutdown_button = gtk_button_new_with_label("Shutdown");
    g_signal_connect(G_OBJECT(shutdown_button), "clicked", G_CALLBACK(shutdown), shutdown_button);

    cancel_button = gtk_button_new_with_label("Cancel");
    g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_quit_cb), NULL);

    gtk_box_pack_start (GTK_BOX(boxl), question, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX(boxl), label, TRUE, TRUE, 0);

    gtk_box_pack_start (GTK_BOX (box), cancel_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(box), shutdown_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(boxl), box, TRUE, TRUE, 10);

    gtk_widget_show_all(window);

    g_timeout_add_seconds(1, _label_update, label);
    continue_timer = TRUE;
    start_timer = TRUE;

    gtk_main();
    return 0;
}
Deps: on debian, install libgtk-3-dev
and compile with:

Code: Select all

gcc  -o timer -fPIC timer.c `pkg-config --cflags --libs gtk+-3.0`
Then run the binary ./timer
Image

Far, far away off the topic and common sense :)
over the seven mountains, seven rivers and seven seas, guarded by seven giants and seven dragons...
there is a sleeping fox in a wallpaper trapped.
https://www.deviantart.com/misko-2083/a ... -759980131
https://www.deviantart.com/misko-2083/a ... -802523362
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License.
For the full resolution there is a download button in the deviant arts page.

Posted: Mon 23 Sep 2019, 20:49
by rufwoof
This will do the same using yad, with the button labels you prefer. Just modify the SHUTDOWNCOMMAND to actually run your shutdown command instead of running geany

Code: Select all

#!/bin/bash

SHUTDOWNCOMMAND=geany

(  echo "99" ; sleep 1
   echo "90" ; sleep 1
   echo "80" ; sleep 1
   echo "70" ; sleep 1
   echo "60" ; sleep 1
   echo "50" ; sleep 1
   echo "40" ; sleep 1
   echo "30" ; sleep 1
   echo "20" ; sleep 1
   echo "10" ; sleep 1 ) |
  yad --progress --title="$TITLE $VERSION" --text=" Are you sure you want to shutdown? \n\n Turning off computer in 10 seconds \n\n Press Cancel to abort shutdown " \
  --percentage=0 --auto-close --auto-kill --button=CANCEL:1 --button=SHUTDOWN:0
[[ $? -eq 0 ]] && $SHUTDOWNCOMMAND

Posted: Mon 23 Sep 2019, 22:00
by misko_2083
rufwoof wrote:This will do the same using yad, with the button labels you prefer. Just modify the SHUTDOWNCOMMAND to actually run your shutdown command instead of running geany

Code: Select all

#!/bin/bash

SHUTDOWNCOMMAND=geany

(  echo "99" ; sleep 1
   echo "90" ; sleep 1
   echo "80" ; sleep 1
   echo "70" ; sleep 1
   echo "60" ; sleep 1
   echo "50" ; sleep 1
   echo "40" ; sleep 1
   echo "30" ; sleep 1
   echo "20" ; sleep 1
   echo "10" ; sleep 1 ) |
  yad --progress --title="$TITLE $VERSION" --text=" Are you sure you want to shutdown? \n\n Turning off computer in 10 seconds \n\n Press Cancel to abort shutdown " \
  --percentage=0 --auto-close --auto-kill --button=CANCEL:1 --button=SHUTDOWN:0
[[ $? -eq 0 ]] && $SHUTDOWNCOMMAND
Thanks but after 3.0 the progress bar no longer works.
So many changes as the newer versions are not backward compatible. No gtk-icons support, right-click notification menu no longer works, entry is deprecated...
It's in quiet unstable now. Probably even more stuff will be removed when the old obsolete code derived from zenity is removed.

Posted: Tue 24 Sep 2019, 02:02
by stemsee
Standalone yad based simple-savefile-creator (mksavefile.sh)

Code: Select all

#!/bin/sh
#
export PROG=$(basename $0)
running=`ps -e | grep -w "$PROG" | wc -l`
[[ "$running" -gt 2 ]] && exit  # run only one instance
deps=`busybox which yad`
[[ -f /etc/DISTRO_SPECS ]] && . /etc/DISTRO_SPECS
if [[ ! -z "$deps" ]]; then
	all=`yad --center --on-top --width=500 --title="Simple-Savefile-Creator" --form --item-separator=" " --field=Size:CBE "512 1024 1534 2048" --field=Filesystem:CBE "ext4 ext2 ext3" --field=ByteSize:CBE "1024 512 64" --field=Name:CBE "changes live-rw fd64save ${DISTRO_FILE_PREFIX}save qsave." --field=Path1:CBE "mnt media" --field=Path2:CBE "sda1 mmcblk0p1 sdb1" --field=Path3:CBE "casper fatdog upupbb Slacko64 EasyOS Quirky"`
	size=`echo $all | cut -f1 -d'|'`
	fs=`echo $all | cut -f2 -d'|'`
	bs=`echo $all | cut -f3 -d'|'`
	savefile=`echo $all | cut -f4 -d'|'`
	Path1=`echo $all | cut -f5 -d'|'`
	PAth2=`echo $all | cut -f6 -d'|'`
	PATh3=`echo $all | cut -f7 -d'|'`
	if [[ "$savefile" == changes* ]]; then
	 savefile="${savefile}.dat"
	elif [[ "$savefile" == fd64save* ]]; then
	 savefile="${savefile}.${fs}"
	elif [[ "$savefile" == $DISTRO_FILE_PREFIX* ]]; then
	 savefile="${savefile}save.`echo $fs | cut -c4`fs"
	fi

fi
if [ -z $(busybox which gxmessage) ]; then
	MESSAGE=xmessage
else
	MESSAGE=gxmessage
fi
[[ -f /tmp/missdeps ]] && rm -f /tmp/missdeps
# check paths....
[[ -z "$deps" ]] && echo "yad was not found" >> /tmp/missdeps
[[ ! -d "/$Path1" ]] && echo "directory /$Path1 not found" >> /tmp/missdeps
[[ -z `mount | grep "$PAth2"` ]] && echo "$PAth2 is not mounted" >> /tmp/missdeps
[[ ! -d "/${Path1}/${PAth2}/$PATh3" ]] && echo "directory not found /${Path1}/${PAth2}/$PATh3" >> /tmp/missdeps
[[ -f "/${Path1}/${PAth2}/$PATh3/$savefile" ]] && echo "/${Path1}/${PAth2}/$PATh3/$savefile already exists !!" >> /tmp/missdeps
missing=`cat /tmp/missdeps`
[[ ! -z "$missing" ]] && $MESSAGE -center "This part of the PATH is problematic
$missing

" -fore black -back green -timeout 6
[[ ! -z "$missing" ]] && exit
yad --center --on-top --text="Does this look right?
		dd if=/dev/zero of=/${Path1}/${PAth2}/${PATh3}/$savefile bs=${bs}k count=$size
		mkfs -t $fs -q -m 0 -F /${Path1}/${PAth2}/${PATh3}/$savefile
"
ret=$?
case $ret in
0) yad --listen --progress --text="Creating Savefile \nPlease Wait" --pulsate --no-buttons --on-top --undecorated --width=200 --height=140 --center &
export prog=$!
dd if=/dev/zero of=/${Path1}/${PAth2}/${PATh3}/$savefile bs=${bs}k count=${size}
mkfs -t $fs -q -m 0 -F /${Path1}/${PAth2}/${PATh3}/$savefile
chmod a+rw /${Path1}/${PAth2}/${PATh3}/$savefile
fsck -M -C -a -l /${Path1}/${PAth2}/${PATh3}/$savefile
kill $prog
[[ ! -z `du -h /${Path1}/${PAth2}/${PATh3}/$savefile | grep "$size"` ]] && yad --text="Savefile creation completed" --timeout=2 --center --no-buttons --undecorted --skip-taskbar --on-top
[[ -z `du -h /${Path1}/${PAth2}/${PATh3}/$savefile | grep "$size"` ]] && yad --text="Savefile creation incomplete" --timeout=2 --center --no-buttons --undecorted --skip-taskbar --on-top;;
1) exit;;
*) exec $0 &
exit;;
esac

Posted: Tue 24 Sep 2019, 06:16
by MochiMoppel
misko_2083 wrote:Bit off topic
Way off topic :lol: , but that's OK. Gives me a good excuse for throwing in another solution .... with Xdialog (we don't have a dedicated thread, do we?)

Xdialog's infobox can be configured to work similar to yad's text-info. Though it accepts only one button and the syntax is a bit weird it is simple and can be quite useful:

Code: Select all

for i in {5..0}; do
	echo  XXX
	echo "Turning off computer in $i seconds"
	echo XXX
	sleep 1
done | Xdialog --cancel-label "Abort shutdown"  -infobox "" 300x100 0
(($?)) && exit
Xdialog  -infobox "Continue now with shutdown commands" 300x100 4000

Posted: Wed 25 Sep 2019, 07:54
by stemsee
How close can yad get to immitating a terminal? or swallowing one?

Posted: Wed 25 Sep 2019, 10:22
by misko_2083
MochiMoppel wrote:
misko_2083 wrote:Bit off topic
Way off topic :lol: , but that's OK. Gives me a good excuse for throwing in another solution .... with Xdialog (we don't have a dedicated thread, do we?)
Aww, I lost the bet. I was betting on Fred the Netherlandian to be the first one to go off topic. :lol:
That's very minimal solution.
stemsee wrote:How close can yad get to immitating a terminal? or swallowing one?
Why reinventing the hot water? :)
Bobby Copper aka YadBashBobby had that idea.
https://www.youtube.com/watch?v=stPAWGXQyLY
Haven't seen him on the forums for a long time.