3

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 [email protected]:/ /media/192.168.1.200 | nautilus /media/192.168.1.200;fusermount -u /media/192.168.1.200'

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

Is possible ?

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

4
  • 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, 2013 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, 2013 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, 2013 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, 2013 at 10:34

2 Answers 2

3
+50

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.

7
  • 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, 2013 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, 2013 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, 2013 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, 2013 at 19:12
  • By the way, if you change the root directory (eg. /media/192.168.1.200/home) then xwininfo -name 192.168.1.200 |grep 'Window id |awk '{print $4}' return No window with name "192.168.1.200" exists! With xwininfo -name 192.168.1.200 |grep 'Window id' |awk '{print $4}' all is ok.
    – georgian
    Feb 10, 2013 at 19:25
2

This work :

#!/bin/bash
sshfs -o idmap=user [email protected]:/ /media/192.168.1.200 | nautilus /media/192.168.1.200
sleep 1
lc_id=`xwininfo -name 192.168.1.200 |grep 'Window id' |awk '{print $4}'`

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

Credits go to @Mahesh

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .