1

I implemented some shell scripts to my dolphin context menue. Within the shells scripts i run some commands, which take some time.

My question is: Is it possible to implement some code into the (a) shell script, so that a pop up window or a status bar in the notification field (kde plasma) is showing up?

Here is the script i want to use the progress bar on:

#!/bin/bash

mkdir small
cp *.jpg small
cp *.JPG small
cd small

for i in *.jpg; do
 if [ -e "$i" ]; then
   file=`basename "$i" .jpg`
   mogrify -unsharp 0.25x0.25+8+0.065 -resize 1280x1024 -normalize -density 180 -monitor "$i"
 fi
done

for i in *.JPG; do
 if [ -e "$i" ]; then
   file=`basename "$i" .JPG`
   mogrify -unsharp 0.25x0.25+8+0.065 -resize 1280x1024 -normalize -density 180 -monitor "$i"
 fi
done

Explanation: The script is very handy to post-process pictures (jpegs) to a reasonable size for picture protocols (ppt, pdf, etc.) or whatelse...

6
  • 1
    For scripts there's zenity which has a progress bar, but that's done in Gtk and may not look good on KDE. For KDE there might be something else but I'm no KDE user so can't suggest Oct 3, 2018 at 8:35
  • Okay...is the bar within the terminal or is there a seperate window opening?
    – benjamin10
    Oct 3, 2018 at 8:37
  • 1
    It's a GUI popup. Basically works on the premise of piping percentage from a loop or subshell to the zenity command with appropriate flags. Here's an example: askubuntu.com/a/931015/295286 Oct 3, 2018 at 8:40
  • Thanks, but the script is just showing the bar but not the actual progress of the commands, which i filled in...Any suggestions
    – benjamin10
    Oct 3, 2018 at 9:19
  • Well, there's not much to be done with commands themselves. If we're talking about commands like cp or find they're built to perform one specific function, and if there's no progress option - there's not much we can do. Oct 3, 2018 at 9:24

1 Answer 1

1

Answer to my question is working but not the most beautiful one ;) It lacks the continuous progress bar in percentage.

Add to the script:

 (#your commands) | zenity --progress --auto-close --title="Post-Process Pictures" --text="Rendering pictures..." --pulsate

This will open a window with the pulsating bar. The window is open as long as the commands are still working.

The Full script now looks like this:

#!/bin/bash

(mkdir small
cp *.jpg small
cp *.JPG small
cd small

for i in *.jpg; do
 if [ -e "$i" ]; then
   file=`basename "$i" .jpg`
   mogrify -unsharp 0.25x0.25+8+0.065 -resize 1280x1024 -normalize -density 180 -monitor "$i"
 fi
done

for i in *.JPG; do
 if [ -e "$i" ]; then
   file=`basename "$i" .JPG`
   mogrify -unsharp 0.25x0.25+8+0.065 -resize 1280x1024 -normalize -density 180 -monitor "$i"
 fi
done) | zenity --progress --auto-close --title="Post-Process Pictures" --text="Rendering pictures..." --pulsate

Best, Benjamin.

Pulsating Progress Bar

Beside: I use the script in combination with a .desktop file, so that i can use it via left-click context menue in dolphin. Just create a resize.desktop file in /usr/share/kservices5/ServiceMenus with the following content:

[Desktop Entry]
Actions=resize_pictures
Icon=transform-crop-resize
MimeType=image/jpeg;
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel

[Desktop Action resize_pictures]
Exec=sh pathtoyourscript/resize_pictures
Icon=transform-scale
Name=Resize Image(s)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.