The time now is Sun 22 Apr 2018, 22:24
All times are UTC - 4 |
Page 21 of 28 [414 Posts] |
Goto page: Previous 1, 2, 3, ..., 19, 20, 21, 22, 23, ..., 26, 27, 28 Next |
Author |
Message |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Mon 17 Apr 2017, 08:27 Post subject:
Re: execute order |
|
@ Geoffrey
My scripts are not running in the Puppy environment but under Ubuntu 16.04 LTS in the folder ~ / .local / share / nemo / scripts. I could install Puppy to test on a USB stick, but the scripts should all be running under Ubuntu.
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 2896 Location: holland
|
Posted: Tue 18 Apr 2017, 18:45 Post subject:
|
|
It could well be a language issue, the output from the shell 'command not found' in german is probably different, so you maybe just need to change this to german:
Code: | if grep -c 'command not found' /tmp/run-command-error; then |
EDIT: Or put this on top of script:
Fred
_________________ Dog Linux website
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Wed 19 Apr 2017, 06:10 Post subject:
|
|
@ Fredx181
With the first code it has already worked. An error message will appear as desired.
@Alles
Thanks for the kind support.
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 2896 Location: holland
|
Posted: Thu 20 Apr 2017, 12:45 Post subject:
|
|
Hi All,
Here's is an experiment of mine (a bit weird, I admit:) ):
Using yad with additional options, e.g. foregound and background color, gradient background and font setting.
Originally meant to be similar as gtkdialog-splash (part of the code taken from it), to be used for simple colored messages, but the good thing is that all yad options can be used also.
Using pango markup can override these extra options (see example 2 and 3 below).
Type ./yad-splash or ./yad-splash --help for the options.
Having installed "gtk2-engines-murrine" is recommended (for e.g. better looking buttons)
(in fact a custom theme file /tmp/gtkrc.yadsplash will be created and used)
You may want to set the icon theme on top of the script, by default it's set to Faenza
ICON_THEME="icon_theme_name"
Example 1, see screenshot 1:
Code: | ./yad-splash --height=80 --width=200 --center --text " \tYellow Text\n \n On Gradient Background " --undecorated --button="gtk-close:1" --fg yellow --bg blue --bg_gradient true --bg_gradient_height 150 --font_name 'Sans Bold 9' |
Example 2, see screenshot 2:
Code: | ./yad-splash --height=100 --width=200 --center --text="<span size='large' foreground='red'><b>\tYad-Splash </b></span> \n \n\tBrown Text\n \n On Gradient Background " --undecorated --no-buttons --fg "#4B200A" --bg "#F4E48F" --bg_gradient true --font_name 'Sans Bold 10' --bg_gradient_height 80 |
Example 3, (example from earlier in this thread, with added color options) see screenshot 3:
Code: | ./yad-splash --title="Golf Club" --height=200 --width=400 --text="<span foreground='blue'><b><big><big>Please enter your details:</big></big></b></span>" \
--form \
--field="<b><big><big>Golflink Number</big></big></b>" \
--field="<b><big><big>Score</big></big></b>" --fg white --bg grey --bg_gradient true --bg_gradient_height 120 --font_name 'Sans Bold 9' |
Fred
Description |
yad-splash, extract and run ./yad-splash [OPTIONS]
|

Download |
Filename |
yad-splash.tar.gz |
Filesize |
2.44 KB |
Downloaded |
97 Time(s) |
Description |
Example 1 |
Filesize |
8.9 KB |
Viewed |
933 Time(s) |

|
Description |
Example 2 |
Filesize |
15.48 KB |
Viewed |
927 Time(s) |

|
Description |
Example 3 |
Filesize |
22.31 KB |
Viewed |
925 Time(s) |

|
_________________ Dog Linux website
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Wed 26 Apr 2017, 08:39 Post subject:
youtube-dl |
|
Hello everybody,
With the command
Youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' - merge output format mp4 "https://www.youtube.com/watch?v=4x0aYzcxmjk"
Downloade I from the Ubuntu Terminal the selected file in the best possible quality in the current directory. Has anyone an idea how I can make the whole thing with yad more comfortable, whereby the url address is of course variable.
Many Thanks
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 2896 Location: holland
|
Posted: Wed 26 Apr 2017, 20:27 Post subject:
|
|
Hi achim, this should do it (with progressbar)
I took parts from here:
https://github.com/Misko-2083/scripts/blob/7ef871dd121e1cb3dbdb2b21ab61ffeeb1d86110/youtube
Code: | #!/bin/bash
# Partly taken from here (and simpified for just one video): https://github.com/Misko-2083/scripts/blob/7ef871dd121e1cb3dbdb2b21ab61ffeeb1d86110/youtube
# function download
download() {
youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' --merge-output-format mp4 --newline -i -o "%(title)s.%(ext)s" "$1" 2>&1 \
| while read line; do
if [[ "$(echo $line | grep '[0-9]*%')" ]];then
percent=$(echo $line | awk '{print $2}')
echo "${percent%.*}%"
fi
if [[ "$(echo $line | grep '\[download\]')" ]];then
progress=$(echo $line | awk '{$1=""; print $0}')
echo "#$progress"
fi
done
RET_YT="${PIPESTATUS[0]}"
if [[ "$RET_YT" = 0 ]]
then
echo "100%"
echo "#Download completed."
else
echo "#Download error."
fi
}
# Enter URL
URL=$(yad --title="YouTube Downloader" --height 100 --width 400 ---center --entry --text=" Please enter url below")
if [ -z "$URL" ]; then # vovchik, if empty, then exit
exit 1
else
# Download with progress bar
download $URL | yad --window-icon="$ICON" \
--progress \
--image=browser-download \
--title="YouTube Downloader" \
--center --borders=6 \
--text=" Downloading: $URL" \
--button="gtk-cancel:1"
fi |
EDIT: Modified to check if $URL is empty, suggestion from vovchik, see below post
Fred
_________________ Dog Linux website
Last edited by fredx181 on Thu 27 Apr 2017, 17:28; edited 1 time in total
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Thu 27 Apr 2017, 13:13 Post subject:
Re: youtube-dl |
|
Hello fredx181
It works so! I thank you for your competent support.
Achim
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1447 Location: Ukraine
|
Posted: Thu 27 Apr 2017, 14:22 Post subject:
|
|
Dear Fred,
How about this at the end, to prevent an unnecessary "downloading" window when the URL is empty?
Code: |
if [ -z "$URL" ]; then
exit 1
else
# Download with progress bar
download $URL | yad --window-icon="$ICON" \
--progress \
--image=browser-download \
--title="YouTube Downloader" \
--center --borders=6 \
--text=" Downloading: $URL" \
--button="gtk-cancel:1"
fi
|
With kind regards,
vovchik
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Thu 27 Apr 2017, 16:57 Post subject:
|
|
Hello vovchik
Good idea, then one can start without any problem possible errors.
achim
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 2896 Location: holland
|
Posted: Thu 27 Apr 2017, 17:30 Post subject:
|
|
vovchik wrote: |
How about this at the end, to prevent an unnecessary "downloading" window when the URL is empty? |
Yes, thanks, much better, edited the script in my above post.
Fred
_________________ Dog Linux website
|
Back to top
|
|
 |
misko_2083

Joined: 08 Nov 2016 Posts: 29
|
Posted: Fri 28 Apr 2017, 09:17 Post subject:
|
|
Glad to help.
Hey fredx181, how would you end the youtube-dl process in the folowing script? Without "killall youtube-dl" of course.
Code: | #!/bin/bash
export ytdownload='@bash -c "download_video %1"'
export ytdpipe=$(mktemp -u --tmpdir pmrp.XXXXXXXX)
mkfifo "$ytdpipe"
trap "rm -f $ytdpipe" EXIT
ytdkey=$(($RANDOM * $$))
function download_video
{
echo "2:@disable@"
echo "#Preparing to download" >> "$ytdpipe"
youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' --merge-output-format mp4 --newline -i -o "%(title)s.%(ext)s" "$1" 2>&1 \
| while read line; do
if [[ "$(echo $line | grep '[0-9]*%')" ]];then
percent=$(echo $line | awk '{print $2}')
echo "${percent%.*}%" >> "$ytdpipe"
fi
if [[ "$(echo $line | grep '\[download\]')" ]];then
progress=$(echo $line | awk '{$1=""; print $0}')
echo "#$progress" >> "$ytdpipe"
fi
done
RET_YT="${PIPESTATUS[0]}"
if [[ "$RET_YT" = 0 ]]
then
echo "100%" >> "$ytdpipe"
echo "#Download completed." >> "$ytdpipe"
else
echo "#Download error." >> "$ytdpipe"
fi
echo "2:$ytdownload"
}
export -f download_video
function ytdl_version () {
echo "#Checking youtube-dl version" >> "$ytdpipe"
wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
if [[ "$?" -ne "0" ]]; then
echo "#Can't connect to youtube-dl server site" >> "$ytdpipe"
fi
ytdlcv=$(youtube-dl --version)
ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
if [[ "$ytdlcv" == "$ytdllv" ]]; then
echo "#youtube-dl is up-to-date" >> "$ytdpipe"
else
echo "#youtube-dl update is available" >> "$ytdpipe"
fi
}
exec 3<> $ytdpipe
yad --plug="$ytdkey" --tabnum=1 --form --field "Enter video url":CE "https://www.youtube.com/" \
--image=browser-download --image-ontop --field="Download!gtk-download:fbtn" "$ytdownload" &
yad --plug="$ytdkey" --tabnum=2 --window-icon="$ICON" \
--progress --borders=6 <&3 &
ytdl_version &
yad --paned --key="$ytdkey" \
--button="Stop":"killall youtube-dl" --text="" --width=500 --height=200 \
--title=$"YouTube Downloader" --image=browser-download --window-icon="$ICON" --center
exec 3>&- |
Edit: Asked the developer how to kill all the processes on paned window close.
Last edited by misko_2083 on Sat 29 Apr 2017, 21:09; edited 1 time in total
|
Back to top
|
|
 |
fredx181

Joined: 11 Dec 2013 Posts: 2896 Location: holland
|
Posted: Fri 28 Apr 2017, 14:27 Post subject:
|
|
misko_2083 wrote: | Very Happy Glad to help.
Hey fredx181, how would you end the youtube-dl process in the folowing script? Without "killall youtube-dl" of course. |
The below works for me (although probably can be better, more simple), but hey! I thought you were the expert
Nice script, btw
EDIT: Changed the "get_pid_and_kill" function to this:
Code: | function get_pid_and_kill () { # fredx181 exec function Stop button (see below)
# export pidytdl="`ps -eo pid,cmd | grep "youtube-dl -f bestvideo \[ext = mp4\] + bestaudio \[ext = m4a\] / bestvideo + bestaudio --merge-output-format mp4 --newline -i" | grep -v grep | awk '{ print $1 }' 2> /dev/null`"
# This will give the unique pid, better than above
export pidytdl="`ps -eo pid,cmd | grep "youtube-dl" | grep "$1" | grep -v grep | awk '{ print $1 }' 2> /dev/null`"
kill $pidytdl
} |
EDIT2: no, still not good, running the script twice with different URL clicking the Stop button kill both youtube-dl processes, so.... I don't know how to get the unique pid, anyone?
EDIT3: Couldn't let go Now it should be fine, actually it's the pid of function 'download_video' that gets killed when clicking the Stop button
Code: | #!/bin/bash
# fredx181, create tempfile, the pid of the function 'download_video' will be written to it
export PIDYTDL=`tempfile 2>/dev/null`
export ytdownload='@bash -c "download_video %1"'
export ytdpipe=$(mktemp -u --tmpdir pmrp.XXXXXXXX)
mkfifo "$ytdpipe"
trap "rm -f $ytdpipe" EXIT
ytdkey=$(($RANDOM * $$))
function download_video
{
echo "2:@disable@"
echo "#Preparing to download" >> "$ytdpipe"
youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' --merge-output-format mp4 --newline -i -o "%(title)s.%(ext)s" "$1" 2>&1 \
| while read line; do
if [[ "$(echo $line | grep '[0-9]*%')" ]];then
percent=$(echo $line | awk '{print $2}')
echo "${percent%.*}%" >> "$ytdpipe"
fi
if [[ "$(echo $line | grep '\[download\]')" ]];then
progress=$(echo $line | awk '{$1=""; print $0}')
echo "#$progress" >> "$ytdpipe"
fi
done & echo $! > $PIDYTDL; wait $! # fredx181 write pid, possibly later used to kill
RET_YT="${PIPESTATUS[0]}"
if [[ "$RET_YT" = 0 ]]
then
echo "100%" >> "$ytdpipe"
echo "#Download completed." >> "$ytdpipe"
else
echo "#Download error." >> "$ytdpipe"
fi
echo "2:$ytdownload"
}
export -f download_video
function ytdl_version () {
echo "#Checking youtube-dl version" >> "$ytdpipe"
wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
if [[ "$?" -ne "0" ]]; then
echo "#Can't connect to youtube-dl server site" >> "$ytdpipe"
fi
ytdlcv=$(youtube-dl --version)
ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
if [[ "$ytdlcv" == "$ytdllv" ]]; then
echo "#youtube-dl is up-to-date" >> "$ytdpipe"
else
echo "#youtube-dl update is available" >> "$ytdpipe"
fi
}
function get_pid_and_kill () { # fredx181 exec function Stop button (see below)
export pidytdl="$(cat $PIDYTDL)"
rm -f $PIDYTDL
kill $pidytdl
}
export -f get_pid_and_kill
exec 3<> $ytdpipe
yad --plug="$ytdkey" --tabnum=1 --form --field "Enter video url":CE "https://www.youtube.com/" \
--image=browser-download --image-on-top --field="Download!gtk-download:fbtn" "$ytdownload" &
yad --plug="$ytdkey" --tabnum=2 --window-icon="$ICON" \
--progress --borders=6 <&3 &
ytdl_version &
yad --paned --key="$ytdkey" \
--button="Stop":"bash -c get_pid_and_kill" --text="" --width=500 --height=200 \
--title=$"YouTube Downloader" --image=browser-download --window-icon="$ICON" --center
exec 3>&- |
Fred
_________________ Dog Linux website
|
Back to top
|
|
 |
misko_2083

Joined: 08 Nov 2016 Posts: 29
|
Posted: Sat 29 Apr 2017, 19:40 Post subject:
|
|
fredx181 wrote: | misko_2083 wrote: | Very Happy Glad to help.
Hey fredx181, how would you end the youtube-dl process in the folowing script? Without "killall youtube-dl" of course. |
The below works for me (although probably can be better, more simple), but hey! I thought you were the expert
Nice script, btw |
Me? An expert? Good one Fred.
Changed some bits.
Code: | #!/bin/bash
export ytdownload='@bash -c "download_video %1"'
# We need this to store the youtube PID
export ytdpid=$(mktemp -u --tmpdir ytpid.XXXXXXXX)
export ytdpipe=$(mktemp -u --tmpdir ytd.XXXXXXXX)
mkfifo "$ytdpipe"
export ytdpipetwo=$(mktemp -u --tmpdir ytd2.XXXXXXXX)
mkfifo "$ytdpipetwo"
trap "rm -f $ytdpipe $ytdpipetwo $ytdpid" EXIT
ytdkey=$(($RANDOM * $$))
function download_video
{
echo "2:@disable@"
# Check if the URL is valid with the spider
if wget -q --spider "$1"; then
echo "#Preparing to download" >> "$ytdpipe"
>"$ytdpid"
while read line; do
if [[ "$(echo $line | grep '[0-9]*%')" ]];then
percent=$(echo $line | awk '{print $2}')
echo "${percent%.*}%" >> "$ytdpipe"
fi
if [[ "$(echo $line | grep '\[download\]')" ]];then
progress=$(echo $line | awk '{$1=""; print $0}')
echo "#$progress" >> "$ytdpipe"
fi
done < "$ytdpipetwo" &
LOOP_PID="$!"
youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' --merge-output-format mp4 --newline -i -o "%(title)s.%(ext)s" "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"
wait $!
if [[ "$?" = 0 ]]
then
echo "100%" >> "$ytdpipe"
echo "#Download completed." >> "$ytdpipe"
kill "$LOOP_PID"
elif [[ ! -s "$ytdpid" ]]; then
echo "#Download canceled" >> "$ytdpipe"
kill "$LOOP_PID"
else
echo "#Download error" >> "$ytdpipe"
kill "$LOOP_PID"
fi
else
echo "#Invalid URL" >> "$ytdpipe"
fi
echo "2:$ytdownload"
}
export -f download_video
function ytdl_version () {
echo "#Checking youtube-dl version" >> "$ytdpipe"
wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
if [[ "$?" -ne "0" ]]; then
echo "#Can't connect to youtube-dl server site" >> "$ytdpipe"
fi
ytdlcv=$(youtube-dl --version)
ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
if [[ "$ytdlcv" == "$ytdllv" ]]; then
echo "#youtube-dl is up-to-date" >> "$ytdpipe"
else
echo "#youtube-dl update is available" >> "$ytdpipe"
fi
}
function get_pid_and_kill () {
if [[ -s "$ytdpid" ]]; then
BCKUPID="$(<$ytdpid)"
>"$ytdpid"
kill $BCKUPID 2>/dev/null
fi
}
export -f get_pid_and_kill
exec 3<> $ytdpipe
exec 4<> $ytdpipetwo
yad --plug="$ytdkey" --tabnum=1 --form --field "Enter video url":CE "https://www.youtube.com/" \
--image=browser-download --field="Download!browser-download:fbtn" "$ytdownload" &
yad --plug="$ytdkey" --tabnum=2 --window-icon="$ICON" \
--progress --borders=6 <&3 &
ytdl_version &
yad --paned --key="$ytdkey" \
--button="Stop":'bash -c "get_pid_and_kill" 2>/dev/null' --text="" --width=500 --height=200 \
--title=$"YouTube Downloader" --window-icon="$ICON" --center
exec 3>&-
exec 4>&- |
Added another named pipe. You can never make enough of those.
This way I can check the exit status of youtube-dl.
or in other words, if the user has canceled and if download has failed.
Also added a check if url is correct "wget -q --spider $URL" (nothing fancy)
Tested, it kills only the current process, leaves that one in another window alone.
Could't find a way to kill the download process in case I click on the window button [X]. Hey, you can't have it all. I whish that yad paned dialog could nuke everything on exit.
This was fun
Back to that internet radio Yad UI I was working on...http://i.imgur.com/oEHIhXP.png
EDIT: I had a huge headake last night.
Forgot to say this: Thank you Fred.
Oh, man, things with paned dialogs are complicated.
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Wed 17 May 2017, 09:32 Post subject:
Fax with YAD |
|
Hello everybody,
I use the WF-3520 multifunction device from Epson among other things also to fax. There is a FAX driver to the device, which I call from the terminal under Ubuntu 16.04 with the command "epfax -P pc-fax -o fax-number = 0236112345678 testfax2.pdf" and send the document.
For some time I have been working enthusiastically with YAD and would like to run this action via a script. The name and fax number are to be queried via a window and then transferred to the command. A good thing would be a history, so I do not have to enter everything again next time. For example, to print a selected file, I use this script:
#! / Bin / bash
Lpoptions -d WF-3520-Series
For i in $ NEMO_SCRIPT_SELECTED_URIS
do
Soffice --invisible --norestore -p $ i
done
This is how I would like to use the FAX driver.
Has anyone from the experts here present a suggestion to the settlement with YAD?
I thank you in advance.
|
Back to top
|
|
 |
achim
Joined: 13 Apr 2017 Posts: 14 Location: 45659, Germany
|
Posted: Fri 19 May 2017, 09:50 Post subject:
Fax with YAD |
|
Hello experts,
To my solution "fax with yad" I have put together the code listed below. It works as far as history. If you have any suggestions for improvement, I would be very happy.
Achim
Code: |
#! /bin/bash
XTERM="xterm"
# create history file
mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache}/
HISTFILE=${XDG_CACHE_HOME:-$HOME/.cache}/ix1-run.history
touch $HISTFILE
# create and run dialog
TITLE="Faxprogramm vorbereiten..."
TEXT="\nFaxnummer eingeben und Enter drücken:\n"
fnr=$(yad --width=500 --center --window-icon="gtk-execute" --name="${0##/}" --title="$TITLE" --text="$TEXT" --image="gtk-execute" --editable --entry --rest $HISTFILE)
TITLE="Faxprogramm starten..."
TEXT="\nName eingeben und Enter drücken:\n"
nam=$(yad --width=500 --center --window-icon="gtk-execute" --name="${0##/}" --title="$TITLE" --text="$TEXT" --image="gtk-execute" --editable --entry --rest $HISTFILE)
# run command
dat="datei.pdf"
epfax -P pc-fax -o fax-number=$fnr $dat
sleep .1
if grep -c 'Befehl nicht gefunden' /tmp/run-command-error; then
yad --fixed --title="Falsche Eingabe!" --image "dialog-warning" --text="\n Die Fax-Nummer \n\n $fnr\n\n ist nicht korrekt,\n bitte noch einmal versuchen! \n" --timeout="10" --no-buttons
rm /tmp/run-command-error
basename "$0"
else
# add command to history
head $HISTFILE | grep -qF "$fnr" || echo -e "$fnr && $nam\n$(<$HISTFILE)" > $HISTFILE
fi
exit 0
|
|
Back to top
|
|
 |
|
Page 21 of 28 [414 Posts] |
Goto page: Previous 1, 2, 3, ..., 19, 20, 21, 22, 23, ..., 26, 27, 28 Next |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|