Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to automatically launch gksudo whenever I open a text file without write permissions in Nautilus? I often need to edit my /etc/hosts file and sometimes I forget to right click and select "Open as administrator".

share|improve this question
    
Are you looking for a solution like nautilus-gksu, which adds an "Open as administrator" item to the context menu, or are you already using it and want a way to do this without using the context menu? –  htorque Jan 9 '11 at 15:56
    
I'm already using it. I'd like not having to right click every time as I often forget. It would be nice if it just would be the default double click action for non writeable files. –  Olivier Lalonde Jan 9 '11 at 16:01
1  
report a wishlist bug - it would be awesome to add this as a feature. –  RolandiXor Jan 10 '11 at 22:23

1 Answer 1

#!/bin/bash
EDITOR=gedit
SUDO=gksu-polkit
test -w "$1" || exec $SUDO $EDITOR "$1"
exec $EDITOR "$1"

Paste that in a file, make executable, and set as default to open whatever files you like. Change the variables if you have a different editor or sudo program.. (Personally, I like gksu-polkit, from the package of the same name, better than gksudo, just because it doesn't grab my screen.)

I assume you know how to do all that; I'm more than happy to help if you don't.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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