Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-01-24 17:05:50

D.dave
Member
Registered: 2019-12-06
Posts: 58

Thunar: quick way to unmount USB disks and storage

Hi,
with the update of Thunar to 4.16, I discovered that the side pane (when set as "Shortcuts") has changed the order: previously I had, in such order:
Devices
Places
Network

Now:

Places
Devices
Network

I prefer have Devices on top, but I cannot figure out how and if is possible to change such order; can someone tell me, if possible, to change such order?

Thank you.

Last edited by D.dave (2021-01-25 20:35:00)

Offline

#2 2021-01-24 18:02:07

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Thunar: quick way to unmount USB disks and storage

Unfortunately no, its not possible to change the order. Have a read through this bug report for the rationale for the change.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2021-01-24 18:21:39

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

OK, I see (I also found it on GitLab and voted for make it configurable: https://gitlab.xfce.org/xfce/thunar/-/issues/447)

The fact is that:

I have a lot of entries under "Places" and when I have to unmount/eject a device, I have to scroll down a lot.
For mount is not a problem: under "Computer" I just do a double click on the disk which I want to mount (or set thunar-volman to automount).

Well, so I'm looking at least to create a Custom action which appears only on mounted disk (USB storages).
I tried to create a custom action: 'udisksctl unmount -b %f' but I cannot figure out how to make it appears on mounted disks: in the options I have set it for directory, but, so, appears only on directories.

Do you have any idea/workaround for this? I lurked the forum a lot and I've seen that you are expert about bash scripting and not only about Xfce :-)

Offline

#4 2021-01-24 21:56:56

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Thunar: quick way to unmount USB disks and storage

It doesn't look like UCA can address mount points. (have you looked at https://docs.xfce.org/panel-plugins/xfce4-mount-plugin.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2021-01-25 08:02:38

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

Thank you for the hint; have it in the panel is very practical.
However, while attempting to insert personal commands, I got "failet to unmount".

My commands for unmount:

sudo sync %d && sudo udisksctl unmount %d && sudo udiskctl power-off %d
Because: I wanto to sync, unmount and power off (power off acts like "eject" from thunar, am I right?)

Furthermore, also If I unmount the devices /from Thunar), in such plugin, the devices disappears and I cannot mount them again from this plugin.

EDIT:

udisksctl unmount -b %d && udisksctl power-off %d works, but the disks, in such case USB HDD, are only unmounted but aren't been ejected/powered off.

From a Terminal, these commands (in such order) properly works:
udisksctl unmount -b /dev/sdc1 #%d
udisksctl power-off -b /dev/sdc1 #%d

But such plugin doesn't run them sequentially...

Last edited by D.dave (2021-01-25 08:50:40)

Offline

#6 2021-01-25 10:45:07

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

I think I've found a solution thanks to bash scripting :-)

#!/bin/bash

listmounted=$(findmnt -o LABEL,SOURCE | grep "/dev" | tail -n +2)
echo "$listmounted" > /tmp/mounted_disk
mapfile -t array < "/tmp/mounted_disk"
#getblocknames=$(findmnt -o LABEL,SOURCE | grep -P "/dev" | awk '{print $NF}' | tail -n +2)

#echo "$listmounted"
#echo "$getblocknames"

choosedisk=$(yad --title="Unmount" --width 210 --height 180 \
--form --item-separator="," \
--field="Choose what unmount:":CB "${array[0]}","${array[1]}")

choosedisk=$(echo "$choosedisk" | tr -d "|" | sed 's:.* ::')
echo $choosedisk

udisksctl unmount -b $choosedisk; udisksctl power-off -b $choosedisk

I'll add such script in a launcher on the panel :-)

The only thing that I still not figured out is how to add more arrays if more disks are mounted; maybe I will add an

if

condition; how do you would achieve this?

Do you think is ok?

EDIT:

Now is:

listmounted=$(findmnt -o LABEL,SOURCE | grep "/dev" | tail -n +2)
echo "$listmounted" > /tmp/mounted_disk
mapfile -t array < "/tmp/mounted_disk"
#getblocknames=$(findmnt -o LABEL,SOURCE | grep -P "/dev" | awk '{print $NF}' | tail -n +2)
arraynumbers=$(wc -l /tmp/mounted_disk | awk '{ print $1 }')


if [ $arraynumbers == 1 ];
then
entrynumbers="${array[0]}"
fi

if [ $arraynumbers == 2 ];
then
entrynumbers="${array[0]},"${array[1]}""
fi

if [ $arraynumbers == 3 ];
then
entrynumbers="${array[0]}","${array[1]}","${array[2]}"
fi

#echo "$listmounted"
#echo "$getblocknames"

#echo -e ${array[*]}

choosedisk=$(yad --title="Unmount" --width 210 --height 180 \
--form --item-separator="," \
--field="Choose what unmount:":CB "$entrynumbers")

choosedisk=$(echo "$choosedisk" | tr -d "|" | sed 's:.* ::')
echo $choosedisk


#udisksctl unmount -b $choosedisk &
#sleep 6
#udisksctl power-off $choosedisk

udisksctl unmount -b $choosedisk; udisksctl power-off -b $choosedisk

And it works: It gave me the enties of mounted disks without empty strings.
But is absurd fill the script of these if conditions

if [ $arraynumbers == 3 ];

Last edited by D.dave (2021-01-25 11:13:46)

Offline

#7 2021-01-25 14:32:54

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

So I ended up with the following script, which automatically populate the available disks to unmount in the YAD's menu:

#!/bin/bash

listmounted=$(findmnt -o LABEL,SOURCE | grep "/dev" | tail -n +2)
echo "$listmounted" > /tmp/mounted_disk
disktounmount=$(cat /tmp/mounted_disk | cut -d/ -f1 | awk '{$1=$1};1' | awk '{ print "\""$0"\","}' | tr -d "\n")

choosedisk=$(yad --title="Unmount" --width 210 --height 180 \
--form --item-separator="," \
--field="Choose what unmount:":CB "$disktounmount")

choosedisk=$(cat /tmp/mounted_disk | grep "$choosedisk" | cut -d " " -f3 )
echo "$choosedisk"

blocktounmount=$(cat /tmp/mounted_disk | grep "$choosedisk" | cut -d " " -f3)


if [ -z "$blocktounmount" ];
then
exit 0
fi

udisksctl unmount -b "$blocktounmount"; sleep 4; udisksctl power-off -b "$blocktounmount"

And is working flawlessy; before unmount the disk and then power it off.
However I want to be sure that I'm doing it in the proper way (eg I inserted sleep 4 between unmount and poweroff; maybe I have to check when the disk has been effectively unmounted instead of rely on fixed time)

EDIT:

Also done this thanks to fuser:

currentaccess=$(fuser -m "$blocktounmount")

until [ -z $currentaccess ]; do
	echo "Something is accessing the disk: these are the PIDS:"
	procname=$(ps -p $currentaccess -o comm=)
	yad --width=250 \
	--image=/home/dave/Pictures/icons/warning-icon_56.png \
	--title "Close remaining processes" --text="Please, close these apps: $procname" --button='Is closed':1
	currentaccess=$(fuser -m /home/dave/mounts/servicedisk)
done

If something is opened on the disk, this warning will appear:

2021-01-25-15-49.png

Last edited by D.dave (2021-01-25 14:53:17)

Offline

#8 2021-01-25 16:46:38

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Thunar: quick way to unmount USB disks and storage

On the "disktounmount..." line, you should also trim off the last "," so you don't have an extra blank line in the list. This should do it:

disktounmount=$(cat /tmp/mounted_disk | cut -d/ -f1 | awk '{$1=$1};1' | awk '{ print "\""$0"\","}' | tr -d "\n" | sed 's/.$//')

Edit:
Also your first line:

listmounted=$(findmnt -o LABEL,SOURCE | grep "/dev" | tail -n +2)

...won't work if someone has more than one hard drive.

Last edited by ToZ (2021-01-25 17:05:19)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#9 2021-01-25 18:18:24

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

Good points, ToZ!
Thank you!

Anyway: can you edit the title of this discussion? Now is no longer about Thunar, or at least "Devices above Places" :-)

Offline

#10 2021-01-25 19:49:34

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Thunar: quick way to unmount USB disks and storage

You can edit the title. Just edit your first post and make the change.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#11 2021-01-25 21:20:57

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

I made a quick GIF recording to shows how such method is so much better and quicker :-)

Peek-2021-01-25-22-16.gif

Offline

#12 2021-01-25 23:04:07

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,950

Re: Thunar: quick way to unmount USB disks and storage

Nice. Can you post back your final code?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#13 2021-01-25 23:11:41

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

Sure.
And also many thanks to you for your assistance.

#!/bin/bash

listmounted=$(findmnt -o LABEL,SOURCE | grep "/dev" | tail -n +2)

echo "$listmounted" > /tmp/mounted_disk
disktounmount=$(cat /tmp/mounted_disk | cut -d/ -f1 | awk '{$1=$1};1' | awk '{ print "\""$0"\","}' | tr -d "\n" | sed 's/.$//')

iconunmount=/home/dave/Pictures/icons/drive-harddisk-usb-UNMOUNT-100px.png
choosedisk=$(yad --title="Unmount" --width 210 --height 180 \
--image="$iconunmount" \
--form --item-separator="," \
--field="Choose what unmount:":CB "$disktounmount")

choosedisk=$(cat /tmp/mounted_disk | grep "$choosedisk" | cut -d " " -f3 )
echo "$choosedisk"

blocktounmount=$(cat /tmp/mounted_disk | grep "$choosedisk" | cut -d " " -f3)

if [ -z "$blocktounmount" ];
then
exit 0
fi


currentaccess=$(fuser -m "$blocktounmount")

until [ -z $currentaccess ]; do
	echo "Something is accessing the disk: these are the PIDS:"
	procname=$(ps -p $currentaccess -o comm=)
	yad --width=300 \
	--image=/home/dave/Pictures/icons/warning-icon_56.png \
	--title "Close remaining processes" --text="Please, close these apps: $procname" --button='Is closed':1
	currentaccess=$(fuser -m "$blocktounmount")
done

udisksctl unmount -b "$blocktounmount"

waitunmount=$(df -h | grep "$blocktounmount")
until [[ -z $waitunmount ]]; do
	echo "disk is busy, waiting"
	sleep 5
done


udisksctl power-off -b "$blocktounmount"

Last edited by D.dave (2021-01-25 23:12:51)

Offline

#14 2021-01-25 23:57:04

D.dave
Member
Registered: 2019-12-06
Posts: 58

Re: Thunar: quick way to unmount USB disks and storage

D.dave wrote:

Sure.
And also many thanks to you for your assistance.

I forget to say: obviously feel free to give me more suggestions, if in you opinions something is wrong or if could be improved :-)

Offline

Board footer

Powered by FluxBB