I open Nautilus by command line in new window. I want to execute another command after nautilus is closed. Like this :

bash -c 'sshfs -o idmap=user my_user@ /media/ | nautilus /media/;fusermount -u /media/'

In this case, I want to execute fusermount -u /media/ only after Nautilus is closed.

Is possible ?

Addendum: I often multiple Nautilus windows open. So I want to close this window ONLY.

  • There is no straightforward way to do it. I guess the only way to achieve this is to use some script to note the id of the new window, poll if it still exists, and call the next command when the window is destroyed. May be nautilus scripts offer a better way, but not sure. – Mahesh Feb 9 '13 at 7:10
  • Nautilus scripts/actions is certainly not a solution. And and I don't know how to find the id of the new window (this specific window). I guess I'll have to fusermount the filesystem manually... – georgian Feb 10 '13 at 6:40
  • Actually I solved an manual solution . I created a .desktop file who changes his icon depending on the state of fileystem (mounted or unmounted). This is to see that connection has remained mounted for no reason and unmount it with double-click (and icon change to unmounted). If no one will find another solution will stay with it. – georgian Feb 10 '13 at 10:26
  • @Mahesh, I use nautilus-actions after connection is open (filesystem mounted) for edit-delete-create files/folders with root privileges (sudo) over ssh and with scripts located on server and local using expect. – georgian Feb 10 '13 at 10:34

Not a concrete answer, but few pointers that may help.

If the window has a unique title, you can get its window id using

NAUTILUS_WINDOWID=`xwininfo -name <title> |grep 'Window id' |awk '{print $4}'`

Now periodically calling xwininfo -id $NAUTILUS_WINDOWID >/dev/null should do the trick.

It returns 0 if the window exists, and 1 otherwise.

  • 10x @Mahesh, but i don't know why Nautilus has no names to windows. (I use Gnome minimal desktop over Ubuntu server 12.04) – georgian Feb 10 '13 at 18:08
  • The title is usually the foldername. Assuming you have no other windows that have the foldername as title, you should hit the right window with the given command. and re: your comment, what exactly do you mean by 'names to windows' ? – Mahesh Feb 10 '13 at 18:17
  • try xwininfo |grep 'Window id' When it asks you to click a window, click on the nautilus window. That will tell you what its title is (The part in quotes). But anyway, titles not appearing is a weird thing IMO. – Mahesh Feb 10 '13 at 18:54
  • Thank you again. That may be a solution that will study tomorrow. The only problem is how often they check the window state ... I do not know what to say. A while loop with 1 second pause perhaps ... I don't know now. – georgian Feb 10 '13 at 19:12
  • By the way, if you change the root directory (eg. /media/ then xwininfo -name |grep 'Window id |awk '{print $4}' return No window with name "" exists! With xwininfo -name |grep 'Window id' |awk '{print $4}' all is ok. – georgian Feb 10 '13 at 19:25

This work :

sshfs -o idmap=user my_user@ /media/ | nautilus /media/
sleep 1
lc_id=`xwininfo -name |grep 'Window id' |awk '{print $4}'`

while [ ! -z "$(xwininfo -id "$lc_id" | grep "Absolute upper-left X" )" ]
   sleep 1
fusermount -u /media/

Credits go to @Mahesh

  • Glad it helped. :) you can drop that grep "Absolute..." part. Just $(xwininfo -id "$lc_id") should work there. – Mahesh Feb 11 '13 at 18:23
  • You're right. The string is empty anyway. – georgian Feb 13 '13 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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