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.

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@192.168.1.200:/ /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.

share|improve this question
    
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

2 Answers 2

up vote 3 down vote accepted
+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.

share|improve this answer
    
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/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 '13 at 19:25

This work :

#!/bin/bash
sshfs -o idmap=user my_user@192.168.1.200:/ /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

share|improve this answer
    
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

 
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.