pkexec command in a .desktop file

np_3ka

I made a .desktop file for Androxyde's Flashtool (utility for Sony Xperia devices that I have to open with an executable file in its folder) that requires root privileges to use fastboot utilities. I used to make it work with gksu, but I'm on Ubuntu 15.04 and gksu is now old.

I tried to modify the exec line from

Exec=gksu /home/natasha/FlashTool/FlashTool
to
Exec=pkexec /home/natasha/FlashTool/FlashTool
Then, I read about pkexec doesn't allow to run X11 applications and so I override in this way:

enter image description here

Link to full image on Imgur.com

The problem now is: It asks me the password but the Flashtool's GUI doesn't start. BUT if I execute that command in terminal, the program starts without problems. What can I do?

enter image description here

Link to full image on Imgur.com

A.B.

Create a new file in /usr/share/polkit-1/actions/

sudo nano /usr/share/polkit-1/actions/FlashTool.policy

and add the lines below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

<policyconfig>

  <action id="org.freedesktop.policykit.pkexec.run-FlashTool">
    <description>Run FlashTool</description>
    <message>Authentication is required to run FlashTool</message>
    <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/home/natasha/FlashTool/FlashTool</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
  </action>

</policyconfig>

Then create a new file /home/natasha/FlashTool/

nano /home/natasha/FlashTool/flashtool-pkexec

and add the lines below:

#!/bin/sh
pkexec "/home/natasha/FlashTool/FlashTool" "$@"

Use the line below for Exec in your desktop file:

Exec=/home/natasha/FlashTool/flashtool-pkexec

Tested on my system Ubuntu 15.04 GNOME with the following files:


$ cat /usr/share/applications/gedit.root.desktop 
[Desktop Entry]
Name=Gedit as root
GenericName=Text Editor
X-GNOME-FullName=
Comment=
Exec=gedit-pkexec
Icon=gedit
Terminal=false
Type=Application
Categories=GNOME;System;Filesystem;Settings;
StartupNotify=true
X-Ubuntu-Gettext-Domain=gedit

$ cat /usr/share/polkit-1/actions/gedit.policy 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

<policyconfig>

  <action id="org.freedesktop.policykit.pkexec.run-FlashTool">
    <description>Run FlashTool</description>
    <message>Authentication is required to run FlashTool</message>
    <defaults>
      <allow_any>no</allow_any>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/gedit</annotate>
    <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
  </action>

</policyconfig>

$ cat /usr/bin/gedit-pkexec 
#!/bin/sh
pkexec "gedit" "$@"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

pkexec command in a .desktop file

From Dev

Can I use pkexec in a python script or a .desktop file?

From Dev

Can I use pkexec in a python script or a .desktop file?

From Dev

One prompt pkexec - two command

From Dev

.desktop file :line 1: [Desktop: command not found

From Dev

Create a .desktop file that opens and execute a command in a terminal

From Dev

desktop file in ubuntu does not execute command

From Dev

Create a .desktop file that opens and execute a command in a terminal

From Dev

file is visible on my desktop but not via the ls command

From Dev

cd command is not functioning in Terminal "desktop: No such file or directory"

From Dev

Start openvpn client command from a Desktop File?

From Dev

How can I create new "gksu" command based on pkexec?

From Dev

How can I do command substitution in a .desktop file?

From Dev

'.desktop' file doesn't show up in 'ls' command list

From Dev

'mpsyt' command runs from terminal but not from .desktop file?

From Dev

Command argument from desktop file ignored in gnome3

From Dev

Linux command to move file from desktop to phone on home network

From Dev

Is there a way to import a file into Github without using the desktop version or command line?

From Dev

How to mark a .desktop file as trusted from command line on Ubuntu 18.04?

From Dev

Create a new file in any desktop using an excel file with a command button to execute that task

From Dev

A command for showing desktop

From Dev

change directory command to desktop

From Dev

Keyboard command to change desktop

From Dev

change directory command to desktop

From Dev

A command for showing desktop

From Dev

Is there a keyboard command for 'show desktop'?

From Dev

Run .desktop command verbose

From Dev

How do I write a command for the Exec key in a .desktop file containing a reserved character correctly?

From Dev

Netbeans desktop shortcut file not working in Unity launcher, Exec command works in term

Related Related

  1. 1

    pkexec command in a .desktop file

  2. 2

    Can I use pkexec in a python script or a .desktop file?

  3. 3

    Can I use pkexec in a python script or a .desktop file?

  4. 4

    One prompt pkexec - two command

  5. 5

    .desktop file :line 1: [Desktop: command not found

  6. 6

    Create a .desktop file that opens and execute a command in a terminal

  7. 7

    desktop file in ubuntu does not execute command

  8. 8

    Create a .desktop file that opens and execute a command in a terminal

  9. 9

    file is visible on my desktop but not via the ls command

  10. 10

    cd command is not functioning in Terminal "desktop: No such file or directory"

  11. 11

    Start openvpn client command from a Desktop File?

  12. 12

    How can I create new "gksu" command based on pkexec?

  13. 13

    How can I do command substitution in a .desktop file?

  14. 14

    '.desktop' file doesn't show up in 'ls' command list

  15. 15

    'mpsyt' command runs from terminal but not from .desktop file?

  16. 16

    Command argument from desktop file ignored in gnome3

  17. 17

    Linux command to move file from desktop to phone on home network

  18. 18

    Is there a way to import a file into Github without using the desktop version or command line?

  19. 19

    How to mark a .desktop file as trusted from command line on Ubuntu 18.04?

  20. 20

    Create a new file in any desktop using an excel file with a command button to execute that task

  21. 21

    A command for showing desktop

  22. 22

    change directory command to desktop

  23. 23

    Keyboard command to change desktop

  24. 24

    change directory command to desktop

  25. 25

    A command for showing desktop

  26. 26

    Is there a keyboard command for 'show desktop'?

  27. 27

    Run .desktop command verbose

  28. 28

    How do I write a command for the Exec key in a .desktop file containing a reserved character correctly?

  29. 29

    Netbeans desktop shortcut file not working in Unity launcher, Exec command works in term

HotTag

Archive