I have an application which does this:
#!/bin/bash
tmpfile=$(mktemp)
gedit $tmpfile && pkexec mv $tmpfile $1
Works great. It creates a temp file, opens it in a graphical editor, and it gets moved to a correct spot with elevated permissions using polkit when I'm done.
But... you need to have gedit installed. I'd prefer to use something which respects the user's desktop environment and preferences. xdg-open
should work but I have a problem:
#!/bin/bash
tmpfile=$(mktemp)
xdg-open $tmpfile && pkexec mv $tmpfile $1
xdg-open
is a forking process. It will launch the editor, then return immediately... causing the mv
to be triggered before I've had a chance to work.
Is there a way for me to only trigger the pkexec mv ...
after the editor completes?
xdg-open(1)
doesn't offer any help. Am I going to need to write some kind of inotify
tool to block until some event is read from an FD?
sudoedit
, but the latter’s UX might not match your expectations. – Stephen Kitt Apr 21 '20 at 15:35pkexec
.sudo
andsudoedit
don't really work well from inside of an unprivilaged GUI. Actually, writing to a tempfile with the user's editor, then moving it was an idea I got fromvisudo
. – Stewart Apr 21 '20 at 15:40gedit
, then running your first example — the temporary file will open in the running editor and yourpkexec
will proceed without waiting. Some editors can be asked to wait (see here), butxdg-open
doesn’t have anything equivalent. – Stephen Kitt Apr 21 '20 at 15:45mimeopen -n
instead – A.B Apr 22 '20 at 02:23inotify
when I saw your answer. – Stewart Apr 22 '20 at 09:42mimeopen
doesn’t necessarily wait either, it doesn’t do anything special; on my system, opening withgedit
usingmimeopen
doesn’t wait if the editor is already running. – Stephen Kitt Apr 22 '20 at 14:52