script-2-desktop

Moderator: Forum moderators

Post Reply
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

script-2-desktop

Post by stemsee »

Here is a utility script to automate building desktop files for your scripts.

Put this script in /root/ and make executable.

It needs an sh directory in /root. place scripts with .sh extension in there. Make an icon directory inside /root/sh/icons ... place icon, named same as script without .sh extension, in /root/sh/icons dir (and it must be a .png image).

Finally click on this script /root/script-2-desktop.sh

A yad --icons gui showing the self-executing desktop files will open. This is handy in case you don't want to add your scripts to the menu, but still want to have an easy visually identifiable file to execute your script with. These files are readily relocatable.

xscreenshot-20241016T224933.png
xscreenshot-20241016T224933.png (30.9 KiB) Viewed 227 times

Code: Select all

#!/bin/bash
# by stemsee
[ ! -d /root/sh/icons ] && mkdir -p /root/sh/icons
[ ! -d /root/apps ] && mkdir -p /root/apps
# add script name here without .sh extension. one per line.
list=''
echo -e "$list" | grep -v -e '^$' | sed -e 's/ //g' -e 's/\n/ /g' | while read line
do
if [[ ! -z "$line" ]]; then
NAME="$line"
[[ ! -d /root/apps/"$NAME".desktop ]] && echo -e "[Desktop Entry]
Name=$line
Version=1.0
Comment=
Exec=/bin/bash -c \"eval exec /root/sh/$line.sh\"
Icon=/root/sh/icons/$NAME.png
StartupNotify=false
Terminal=false
Type=Application
" > /root/apps/"$NAME".desktop
fi
done

yad --title="script.desktop" --geometry=1116x182+316+43 --icons --read-dir=/root/apps --monitor --no-buttons --skip-tray  &
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: script-2-desktop

Post by stemsee »

I made a series of *-2-desktop scripts which I will post here.

Update for script-2-desktop.sh list is compiled by the ls command, but the subsequent manual list can override the first list variable definition, for less inclusive entries.

Code: Select all

#!/bin/bash
# by stemsee
[[ ! -d /root/sh/icons ]] && mkdir -p /root/sh/icons
[[ ! -d /root/apps/scripts ]] && mkdir -p /root/apps/scripts
list=$(ls *.sh  | cut -f1 -d'.')
#list='scrcpy
#asound-2-profiles
#funnel
#mount-and-share
#snapp
#start-edge
#tailscale
#ts-chat'
echo "$list" | while read line
do
if [[ -f /root/sh/icons/"$line".png ]]; then
echo -e "[Desktop Entry]
Name=$line
Version=1.0
Comment=
Exec=/bin/bash -c \"eval exec /root/sh/$line.sh\"
Icon=/root/sh/icons/$line.png
StartupNotify=false
Terminal=false
Type=Application
" > /root/apps/scripts/"$line".desktop
fi
done

yadu --title="script.desktop" --geometry=291x1289+28+4 --icons --read-dir=/root/apps/scripts --monitor --no-buttons --skip-tray  --on-top &

bt-2-desktop.sh, 'bluetoothctl devices' feeds the list and the commands that act upon the device mac address are pair and connect.

Code: Select all

#!/bin/bash
# by stemsee
[[ ! -d /root/apps/bt ]] && mkdir -p /root/apps/bt
bluetoothctl devices | while read line
do
Name=$(echo $line | cut -f3 -d' ')
MAC=$(echo $line | cut -f2 -d' ')
echo -e "[Desktop Entry]
Name=$Name
Version=1.0
Comment=Bluetooth device
Exec=/bin/bash -c \"service bluetoothd start 2>/dev/null; bluetoothctl pair $MAC 2>/dev/null;bluetoothctl connect $MAC \"
Icon=/root/sh/icons/bt-2-desktop.png
StartupNotify=false
Terminal=false
Type=Application
NoDisplay=true" > /root/apps/bt/"$Name".desktop
done
yad --title="bluetooth-$Name" --geometry=1116x182+316+43 --icons --read-dir=/root/apps/bt --monitor --no-buttons --skip-tray  &

book-2-reader.sh for pdf epub doc odg etc i use fatdog apps, specify reader variable according to your preference.

Code: Select all

#!/bin/bash
# by stemsee
[[ ! -d /root/apps/books ]] && mkdir -p /root/apps/books
ls /root/docs/*{.epub,*.pdf,*.txt,*.odf,*.odg.*.doc,*.docx,*.xl} | while read line
do
shopt -s nocasematch
case "$line" in
*.png|*.jpg|*.bmp) reader="viewnior $line";;
*.pdf) reader="evince $line";;
*.epub) reader="cr3 $line";;
*.txt|*.lst|*.conf|*.doc*|*.odf|*.odg|*.xl|*.sh|*) reader="libreoffice $line"
esac
export reader
Name=$(basename $line)
echo -e "[Desktop Entry]
Name=$Name
Version=1.0
Comment=Book
Exec=/bin/bash -c \"$reader \"
Icon=/root/sh/icons/book-2-desktop.png
StartupNotify=false
Terminal=false
Type=Application
NoDisplay=true" > /root/apps/books/"$Name".desktop
done
yad --title="books" --geometry=1116x182+316+43 --icons --read-dir=/root/apps/books --monitor --no-buttons --skip-tray  &

wifi-2-desktop.sh, this is tailored for snapp wifi profile configs which are saved as $ssid+$mac , change accordingly

Code: Select all

#!/bin/bash
# by stemsee
[[ ! -d /root/apps/wifi ]] && mkdir -p /root/apps/wifi
INTERFACE=$(iw dev | grep -e 'phy#0' -e 'Interface' | cut -f2 -d' ' | tail -n1)
list=$(ls /root/.config/snapp/profiles/*+*)
#list='
#
#'
echo "$list" | while read line
do
echo -e "[Desktop Entry]
Name=$(basename $line)
Version=1.0
Comment=Wifi-Access-Point
Exec=/bin/bash -c \"rm -rf /var/run/wpa_supplicant/$INTERFACE;wpa_supplicant -i$INTERFACE -Dwext -c$line -B; udhcpc -q -i$INTERFACE \"
Icon=/root/.config/snapp/icons/wifi.png
StartupNotify=false
Terminal=false
Type=Application
NoDisplay=true" > /root/apps/wifi/"$(basename $line)".desktop
done
yad --title="wifi" --geometry=1116x182+316+43 --icons --read-dir=/root/apps/wifi --monitor --no-buttons --skip-tray  &

media-2-desktop.sh should be music or videos

Code: Select all

#!/bin/bash
# by stemsee
[[ ! -d /root/apps/media ]] && mkdir -p /root/apps/media
for i in pmusic mplayer ffplay mpv vlc
do
[[ "$(type -p $i)" ]] && PLAYER="$i"
done
list=$(ls /root/media/*)
#list='
#
#'
echo -e "$list" | while read line
do
NAME=$(basename "$line")
echo -e "[Desktop Entry]
Name=$NAME
Version=1.0
Comment=Media File
Exec=/bin/bash -c \"$PLAYER '$line' \"
Icon=/root/sh/icons/media-2-desktop.png
StartupNotify=false
Terminal=false
Type=Application
NoDisplay=true" > /root/apps/media/"$NAME".desktop
done
yad --title="media.desktop" --geometry=400x1182+1400+100 --icons --read-dir=/root/apps/media --monitor --no-buttons --skip-tray  &

radiolst-2-desktop.sh

Code: Select all

#!/bin/bash
# by stemsee
[ ! -d /root/my-documents ] && mkdir -p /root/my-documents
for i in pmusic mplayer ffplay mpv vlc
do
	[[ "$(type -p $i)" ]] && PLAYER="$i"
done
for i in $(ls /root/radiolist/playlist.*)
do

cat "$i" | while read line
do
if [[ ! -z "$line" ]]; then
URL="$(echo $line | cut -f1 -d'|')"
if [[ ! -z "$URL" ]]; then
NAME="$(echo $line | cut -f2 -d'|')"
[[ ! -d /root/my-documents/"$i" ]] && mkdir -p /root/my-documents/"$i"
[[ ! -d /root/my-documents/"$i"/"$NAME".desktop ]] && echo "[Desktop Entry]
#URL=$URL
Name=$NAME
Version=1.0
Comment=
Exec=/bin/bash -c \"export URL='"$URL"'; export NAME='"$NAME"'; export ICON='icons/search.png'; $PLAYER $URL \"
Icon=/root/.dogradio2/data/icons/search.png
StartupNotify=false
Terminal=false
Type=Application
" > /root/my-documents/"$i"/"$NAME".desktop
[[ ! -z $(grep "\">here</a>.</p>'" /root/my-documents/"$i"/"$NAME".desktop) ]] && sed -i "s|\"\>here\<\/a\>\.\<\/p\>\'||g" /root/my-documents/"$i"/"$NAME".desktop
fi
fi
done
done

example radio station list playlist.Favourites

Code: Select all

http://jazz-wr05.ice.infomaniak.ch/jazz-wr05-128.mp3|Jazz Radio.fr Contemporary Jazz France Jazz
http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3|Jazz Radio.fr Electro Swing France Jazz-Swing
http://jazz-wr06.ice.infomaniak.ch/jazz-wr06-128.mp3|Jazz Radio.fr Funk France Funk
http://jazz-wr07.ice.infomaniak.ch/jazz-wr07-128.mp3|Jazz Radio.fr Gospel France Christian-Gospel
http://jazz-wr08.ice.infomaniak.ch/jazz-wr08-128.mp3|Jazz Radio.fr Groove France Jazz-Swing
http://jazz-wr13.ice.infomaniak.ch/jazz-wr13-128.mp3|Jazz Radio.fr Groove'up France Electronica
http://jazz-wr14.ice.infomaniak.ch/jazz-wr14-128.mp3|Jazz Radio.fr Happy Hour Radio France Jazz-Easy Listening

http://113fm-edge1.cdnstream.com/1725_128|.113FM The Wave USA Jazz
http://stream.radioparadise.com/aac-320|Radio Paradise USA Eclectic
http://icyrelay.181.fm/181-beatles_128k.mp3|fm1.co.il Beatles Israel Rock
http://relay5.181.fm:8700/|181.fm Chilled Out USA Electronica-Chillout
http://streams.radio.co/s14193ab17/listen|Dance Groove USA Dance

http://air.radioart.com/fCool_jazz.mp3?dlid=|Radio Art Cool jazz Greece Jazz-Easy Listening
http://air.radioart.com/fFusion.mp3?dlid=|Radio Art Fusion Greece Jazz
http://air.radioart.com/fJazz_piano.mp3?dlid=|Radio Art Jazz piano Greece Jazz-Classical
http://air.radioart.com/fJust_jazz.mp3?dlid=|Radio Art Just Jazz Greece Jazz
http://air.radioart.com/fShakuhachi.mp3|Radio Art Shakuhachi Greece Jazz-Easy Listening
http://air.radioart.com/fSmooth_jazz.mp3?dlid=|Radio Art Smooth jazz Greece Jazz-Smooth
http://air.radioart.com/fSwing.mp3?dlid=|Radio Art Swing Greece Jazz-Swing

http://air.radioart.com/fVocal_jazz.mp3?dlid=|Radio Art Vocal Jazz Greece Jazz
http://paineldj5.com.br:8147/stream?type=.mp3|Rio Verde FM Brazil Jazz-Easy Listening
http://69.175.13.131:8280/|BLUE BOSSA NOVA Coolest Brazilian Jazzn Bossa from Rio de Janeiro Another PAUL IN RIO Radio. jazz
http://187.85.121.1:8000/;|Furb FM Brazil Jazz
http://noasrv.caster.fm:10124/stream|Princesa fm 104.9 Brazil Jazz
Post Reply

Return to “Utilities”