Code: Select all
export z
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 '(( ))'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
Code: Select all
z=$((z + 1)); echo "z=$z" >/tmp/z
Code: Select all
. /tmp/z
Code: Select all
. /tmp/MYNAME
echo "$z"
12
Code: Select all
cat /tmp/MYNAME
z=12
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
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
^It was hard to decode what the writer wanted to say.stemsee wrote: How to make it send as it is being typed without newlines until return is hit??
I see the trick! refresh after each character while remembering all previous typing.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
even better with --tail optionCode: 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
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
^It was hard to decode what the writer wanted to say.stemsee wrote: How to make it send as it is being typed without newlines until return is hit??
Try this:stemsee wrote:backspace is not possible!?
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
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;
}
Code: Select all
gcc -o timer -fPIC timer.c `pkg-config --cflags --libs gtk+-3.0`
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.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 geanyCode: 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
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
Way off topic , 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?)misko_2083 wrote:Bit off topic
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
Aww, I lost the bet. I was betting on Fred the Netherlandian to be the first one to go off topic.MochiMoppel wrote:Way off topic , 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?)misko_2083 wrote:Bit off topic
Why reinventing the hot water?stemsee wrote:How close can yad get to immitating a terminal? or swallowing one?