Ubuntu: Replacing gksudo with pkexec: editor doesn't start in current folder



Question:

I'm trying to be a good boy and stop using gksudo, especially since it just got orphaned in the 18.04 daily builds (note, this question is not specific to 18.04).

In the bad old days of using gksudo, I'd typically navigate to a folder containing the file I wish to edit (I use pcmanfm) then select Tools/Open Current Folder In Terminal from the menu. Then I'd type gksudo leafpad [file-I-wish-to-edit] in the newly opened terminal.

Using information in the very useful answer How to configure pkexec? I set my .bash_aliases and I am able to now type pkexec leafpad [file-I-wish-to-edit] in the newly opened terminal and I don't get any errors. Sadly, though I get a blank file instead of what I wanted. I have determined that this is because leafpad is looking in /root instead of the folder I wished to be in.

How can I maintain my halo, continue to use pkexec instead of gksudo, yet retain the functionality I'm used to?


Solution:1

As mentioned in comments, gksu was "orphaned" in 16.04 but you can still install it with:

sudo apt install gksu  

That said I made a wrapper script for pkexec a long time ago that might be of some interest:

#!/bin/bash    # Usage: gsu gedit file1  #  -OR-  gsu natuilus /dirname    COMMAND="$1" # extract gedit or nautilus  ABSOLUTE_NAME=$(realpath "$2")    pkexec "$COMMAND" "$ABSOLUTE_NAME"    #log-file "$ABSOLUTE_NAME" ~/bin/log-gsu-"$COMMAND"  

I named the wrapper gsu as a short form of gksu. The log-file script is a separate project which I commented out in the script for this answer.

You need to setup gedit and nautilus policy kits before you can use this script as the comments reference. In your case you would need to setup a policy kit for leafpad.

Hope this helps!


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »