Desktop entry, or other convinent but safe way to exec multiple statements,

I’m running Gnome on Ubuntu 15.4.

I want to execute two or more actions at once, but let’s try with two:

  • sudo pm-suspend
  • gnome-screensaver-command -l

pm-suspend has been added and allowed to be executed without providing passwords by specifying:

%sudo ALL = (root) NOPASSWD: /usr/sbin/pm-suspend`

documentation – Exec, and exec variables/actions have no references if having multiple Exec is possible, but unfortunately:

[Desktop Entry]
_Name=Sleep and logout
_GenericName=Sleep and logout

#Exec=gnome-screensaver-command -l & sudo pm-suspend # does not work

#Exec=gnome-screensaver-command -l
#Exec=sudo pm-suspend                                # does not work either

Terminal=false
Type=Application
Categories=System;Security;

I’m open to any other suggestions how to achieve given functionality except:

  • make a script and run it as sudo or similar – I consider solutions basing on this insecure, let’s not delve into that matter
  • use gnome power switch or whatever that is called (top right corner) – mine does not have an option to suspend

also, while I’d be happy to have that what is stated above, I’d be even more happy to have an answers that say how to launch multiple different commands (without script/compiling own binary etc), in case I’d like to bundle and automate some other actions.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

To run multiple commands in one launcher, you need to use the following syntax:

Exec=/bin/bash -c "command_1 & command_2"

or, if the second one should wait for the first one to terminate successfully:

Exec=/bin/bash -c "command_1 && command_2"

or, as suggested by Bytecommander (thanks for the completion!), if command_2 should wait for command_1 to finish, but run anyway no matter if command_1 finishes succesfully or not:

Exec=/bin/bash -c "command_1 ; command_2"

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply