Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2081  / 2 Years ago, wed, september 28, 2022, 7:13:07

In my bash script I mount partitions, check them, copy files to them, and unmount. When the script mounts the partition, Nautilus pops up with a Window showing the partition and stealing focus. This is something I want to avoid.



Note: I know I can change the behaviour of this in System settings, Details, Removable media, Never prompt or start programs on media insertion, but I don't want to change the behaviour e.g. if a USB stick is plugged in, I just want to prevent it in my bash script. Since this script runs on other users' computers I cannot modify these settings (in the script) because if it is terminated abnormally it will leave the modified settings in place (I also don't believe it should be necessary to do this).



Actually this auto display doesn't seem consistent. If I do the exact same command from the terminal, Nautilus doesn't show, and I know there are other mounts in my script that don't show. So what could be causing this? Here's an example of the code (both cause separate nautilus windows to pop):



mount $dev $target
mkdir -p $target/home
mount $homedev $target/home


I'm interested in understanding the process by which the mount signals Nautilus and why this is happening (when it doesn't if I mount the partition from the terminal). And what is the best way to prevent this from happening.



I noticed this behaviour starting on release 11.10 (if I recall correctly). I'm currently running 12.04, but the script has to work on all supported releases. I don't believe the solution should involve modifying system settings (that might differ between releases). For example, if you look at other things that mount partitions (like os-prober), there are no nautilus windows popping up when it mounts different partitions.



The script can be found here. And here's the part where Nautilus pops. I think it also pops here, but I've been focusing my testing on the first link. This is where it doesn't pop, called prior to those other mounts - note I've rewritten the first ones as --read-only and within an if statement and it makes no difference.



Ideally the answer will explain why this is happening and how to prevent it, in other words, explain why the in-script mount is treated differently to the one issued from a terminal. A good workaround will also be accepted if it is a fully explained solution and practical that can support all desktop environments (ubuntu, kubuntu, xubuntu, lubuntu etc) - I also want to avoid an exponential increase in testing to verify it.



Thanks in advance



============



Solution as per papashou's link:



add_udev_rules ()
{
for i in "$dev" "$homedev" "$bootdev" "$usrdev"; do
if [ -n "$i" ]; then
block=${i#/dev/}
echo "KERNEL=="""$block""",ENV{UDISKS_PRESENTATION_HIDE}="1"" >> "$wubi_move_dir"/wubi_move.rules
fi
done
cp "$wubi_move_dir"/wubi_move.rules /etc/udev/rules.d/wubi_move.rules
udevadm trigger > /dev/null 2>&1
}

remove_udev_rules ()
{
rm /etc/udev/rules.d/wubi_move.rules
rm "$wubi_move_dir"/wubi_move.rules
udevadm trigger > /dev/null 2>&1
}


This achieves the desired result, but feels like a sledgehammer approach. I believe there is probably a fine-tuning in udev that will allow the partition to still show in Nautilus (and other file browsers) without popping up when it's mounted. By the way if anyone wants to try this, the following script will show the pop-up effect of nautilus:



mkdir -p /tmp/testmount
mount /dev/sda1 /tmp/testmount
sleep 3
umount /dev/sda1
mount /dev/sda1 /tmp/testmount
sleep 3
umount /dev/sda1
mount /dev/sda1 /tmp/testmount
sleep 3
umount /dev/sda1
mount /dev/sda1 /tmp/testmount
sleep 3
umount /dev/sda1
rmdir /tmp/testmount


I'm going to keep playing with udev and I've also filed a bug, since this doesn't make any sense for a partition that's not inserted to act like an inserted USB/media card upon mount. Also the udevadm trigger is not an inexpensive operation that appears (on 12.04 at least) to temporarily freeze everything.



So, in summary, I have a workable solution (thanks to everyone who helped out), which I may or may not implement (not sure yet); but I'll keep looking for something else.
Thanks


More From » nautilus

 Answers
5

Try this suggestion: http://www.worldofnubcraft.com/969/hide-your-disks-or-partitions-from-nautilus/



I'm fairly sure it has to do with udev signals and processing.


[#39331] Thursday, September 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tocklftime

Total Points: 110
Total Questions: 109
Total Answers: 100

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;