LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 01-25-2022, 05:23 AM   #1
hish2021
Member
 
Registered: Jan 2021
Posts: 117

Rep: Reputation: Disabled
KDE Plasma Service Menu: can my code be made more concise?


OS: Kubuntu 20.04 with Plasma 5.18.5

I made a "service menu" to use in the Dolphin file manager.

It's purpose is to reduce the brightness of a png/jpg file using ImageMagick's `convert`

Code:
[Desktop Action less-bright]
Exec=convert -brightness-contrast -10x0 %U $(basename -s .png %U)-1.png \
&& convert -brightness-contrast -20x0 %U $(basename -s .png %U)-2.png \
&& convert -brightness-contrast -30x0 %U $(basename -s .png %U)-3.png \
&& convert -brightness-contrast -40x0 %U $(basename -s .png %U)-4.png \
&& convert -brightness-contrast -50x0 %U $(basename -s .png %U)-5.png

Name=Reduce Brightness
Icon=colorneg

[Desktop Entry]
Actions=less-bright

MimeType=image/png;image/jpeg;

ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel
So if I right-click on an image file in Dolphin, I'll get a "Reduce Brightness" entry in the context menu (just like Thunar's custom actions).

Choosing "Reduce Brightness", will produce 5 additional image files of differing brightness:
64-brave-browser-1.png
64-brave-browser-2.png
64-brave-browser-3.png
64-brave-browser-4.png
64-brave-browser-5.png
64-brave-browser.png (original)

My question is this: my Exec line uses `&&` over and over again but is there a better way to do what my script does?
Attached Thumbnails
Click image for larger version

Name:	20220124-164504.png
Views:	6
Size:	15.7 KB
ID:	38203  
 
Old 01-25-2022, 06:38 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
I guess you can put the commands into a shell script and call it from Exec line. Pass %U as parameter to the script

Code:
#!/bin/sh
for u
do
  for i in 1 2 3 4 5
  do
    convert -brightness-contrast -${i}0x0 "$u" "${u%.png}-$i.png"
  done
done
In Bash, {1..5} is the same as 1 2 3 4 5

Last edited by shruggy; 01-25-2022 at 06:49 AM.
 
1 members found this post helpful.
Old 01-25-2022, 07:39 AM   #3
hish2021
Member
 
Registered: Jan 2021
Posts: 117

Original Poster
Rep: Reputation: Disabled
Thank you very much! But could you please explain the magic in
"${u%.png}-$i.png"
as compared to, say,
$(basename -s .png %U)-5.png
 
Old 01-25-2022, 07:52 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,627

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556

See the "${parameter%word}" section of https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

(Actually, just skip this and see the BashFAQ link Shruggy posted below that explains it better.)


Last edited by boughtonp; 01-25-2022 at 07:58 AM.
 
1 members found this post helpful.
Old 01-25-2022, 07:53 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
See BashFAQ/073
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: KDE Plasma 5.23 Gets First Point Release, Plasma Wayland Sees More Improvements LXer Syndicated Linux News 0 10-20-2021 02:36 AM
LXer: KDE Plasma 5.22.3 Improves Support for Flatpak Apps, Plasma Wayland, and More LXer Syndicated Linux News 0 07-07-2021 02:48 AM
LXer: KDE Plasma 5.13 Desktop Reaches End of Life, KDE Plasma 5.14 Arrives October 9 LXer Syndicated Linux News 0 09-15-2018 10:30 PM
LXer: Plasma 5.6 Makes KDE Plasma Desktop Environment More Powerful, Beautiful And Useful? LXer Syndicated Linux News 0 05-12-2016 12:24 PM
Make a simple script more concise Aseem Linux - Newbie 11 09-16-2009 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 10:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration