I wonder if there's a way to create custom pcmanfm action for ejecting usb-drive in lubuntu? I've tried to do this with udisksctl but the --object-path option is giving me this error:

(udisksctl unmount:10926): GLib-GIO-CRITICAL **: g_dbus_object_manager_get_object: assertion 'g_variant_is_object_path (object_path)' failed
Error looking up object with path /media/user/Flash-Drive

And there's no difference of MIME-types between simple folder and mounted drive so "Eject" action is shown on all folders.


Well, it's seems I've found some kind of solution. This is will unmount and power-off your usb-drive

[Desktop Entry]
Tooltip=Eject selected flash drive
Name=Eject flash drive

[X-Action-Profile profile-zero]
Exec=gksudo eject %f
Name=Default profile

Also you can use it without gksudo prompt after adding setuid to /usr/bin/eject:

[Desktop Entry]
Tooltip=Eject selected flash drive
Name=Eject flash drive

[X-Action-Profile profile-zero]
Exec=eject %f
Name=Default profile

But this action will be shown on all folders. I still have no idea how to make a difference between usb-drive directory and flash-drive directory. I've seen specification Basenames for .desktop entry which specifies selected file-name (used in empty trash action) so may be there some way to specify file-placement?

Update 2

Okay, I've found appropriate MIME-type according to MIME-info Database - inode/mount-point, but now action isn't shown on any directory at all. What may cause a problem?

[Desktop Entry]
Tooltip=Eject selected drive
Name=Eject drive

[X-Action-Profile profile-zero]
Exec=eject %f
Name=Default profile
  • What is the exact command? – Tim Jun 6 '15 at 14:13
  • udisksctl unmount --object-path /media/user/Flash-Drive – Nicholas V. Jun 6 '15 at 14:15
  • There is no file called /media/user/Flash-Drive – Tim Jun 6 '15 at 14:17
  • This is where my usb-drive automatically mounts. I think i just don't understand --object-path option? – Nicholas V. Jun 6 '15 at 14:21
  • No, your USB mounts at /media/YOURUSERNAME/USBNAME You have to replace user and Flash-Drive with the correct names. – Tim Jun 6 '15 at 14:22

My suggestion is to use the umount command.

With the fdisk -l command and inserting different usb-drives determined as identified, say they are /dev/sdd1

Before creating the actions (file.desktop), create its directory:

mkdir -p ~/.local/share/file-manager/actions

Create and edit the action file (umount.desktop) by using these terminal commands one at a time:

touch ~/.local/share/file-manager/actions/umount.desktop
nano ~/.local/share/file-manager/actions/umount.desktop

Paste the below content in umount.desktop:

[Desktop Entry]
Name=Eject Usb-Drive

[X-Action-Profile profile-zero]
Exec=umount /dev/sdd1
Name=Default profile

I've made more progress on this, but solution is still not ideal:
I am using Lubuntu 16.04 with PCManFM 1.24. For USB pen drives I get "Eject Removable Media", but for USB disk drives, I do not get "Safely Remove Drive" as you do in Nautilus (I only get Unmount).
First issue is to get right-click context on devices where, unfortunately, it seems actions are not supported for devices in the left pane in PCManFM, (or Nautilus, but actions work in left pane in Nemo, but actions are implemented differently in Nemo). I have a work-a-round to this by showing "Devices" icon in left pane by ticking "Devices" under "Show in Places" in Edit-Preferences-Layout, where you can then right click on the device in the right pane as shown in attached link: pcmanfm devices right click image

Second issue is script to safely remove drive: The argument passed to action script in the above example is: computer:///ST1000LM010-9YH146.drive (or just ST1000LM010-9YH146 with %w) which is not ideal - I don't believe it evenly uniquely identifies drive as it does not include the serial number. Below is output from "udisksctl status":

$ udisksctl status
MODEL                     REVISION  SERIAL               DEVICE
WDC WD5000BEVT-22ZAT0     01.01A01  WD-WX70A9903180      sda
Kingston DataTraveler G3  1.00      001CC0EC31D0F081F6071284 sdb
ST1000LM010-9YH146        CC9F      W2M076TD             sdc 

So my script matches the model, so assumes you do not have 2 identical devices plugged in to pick up the device. To implement script create file ~/.local/share/filemanager/actions/eject.desktop

[Desktop Entry]
Name=Safely Remove Drive

[X-Action-Profile profile-zero]
Exec=/home/mike/.local/share/file-manager/actions/eject.sh %w 
Name=Default profile

I have put the script, eject.sh, specified by "Exec" in ~/.local/share/filemanager/actions, but note you cannot use "~" or "$HOME" in a desktop file so you have to specify complete path as I have done above

Script eject.sh should contain:

device=`udisksctl status | awk -v d=$1 '
    gsub("%20"," ",d)
    sub("$"," ",d)  # Add a space on the end to give a more exact match
    sub("^","^",d) # Add ^ to start to give a more exact match
$0 ~ d {
    print "/dev/"$NF
    }' `
if [ "$device" == "/dev" ]
    echo "Removable device not found"
    for dev in `df | awk -v device=$device '$1 ~ device {print $1}' `
        echo "Unmounting "$dev
        udisksctl unmount -b $dev

    echo "Powering off: "$device
    udisksctl power-off -b $device

Your command

udisksctl unmount --object-path /media/user/Flash-Drive

is wrong.

/media/user/Flash-Drive isn't an object path.

  1. Find the object path with this command:

    $ gdbus introspect --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices --recurse --only-properties | grep -E "(readonly .+ (Device(IsMounted|IsDrive|File|MountPaths) ).*|\}|.*\{)" | awk -v RS="};" '/Flash-Drive/'
      node /org/freedesktop/UDisks/devices/sdc1 {
        interface org.freedesktop.UDisks.Device {
            readonly as DeviceMountPaths = ['/media/user/Flash-Drive'];
            readonly b DeviceIsMounted = true;
            readonly b DeviceIsDrive = false;
            readonly s DeviceFile = '/dev/sdc1';
  2. Take the node /org/freedesktop/UDisks/devices/sdc1 via:

    (replace '/\/media\/user\/Flash-Drive/' with your path).

    $ gdbus introspect --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices --recurse --only-properties | grep -E "(readonly .+ (Device(IsMounted|IsDrive|File|MountPaths) ).*|\}|.*\{)" | awk -v RS="};" '/\/media\/user\/Flash-Drive/' | awk '/node/ {print $2}'
  3. and unmount with

    gdbus call --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices/sdc1 --method org.freedesktop.UDisks.Device.FilesystemUnmount []

    Or as AllInOne (replace '/\/media\/user\/Flash-Drive/' with your path):

    gdbus call --system --dest org.freedesktop.UDisks --object-path $(gdbus introspect --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices --recurse --only-properties | grep -E "(readonly .+ (Device(IsMounted|IsDrive|File|MountPaths) ).*|\}|.*\{)" | awk -v RS="};" '/\/media\/user\/Flash-Drive/' | awk '/node/ {print $2}') --method org.freedesktop.UDisks.Device.FilesystemUnmount []
  • You can use --block-device too for a slightly saner interface. You'd still need to look up which block device you needed though. – Oli Jun 6 '15 at 16:52

This answer does use pcmanfm, but I have found it is the most convenient one. TL;DR; use lxpanel to add an icon to gnome-disks.

In details:

In lxpanel right-click and select 'Add / Remove Panel Items'. Add a new 'Application Launch Bar' and position it before (or somewhere around) 'Digital Clock' that should be already there. In the newly added 'Application Launch Bar' add as application the 'Preferences / Disks'. This is the gnome-disks application that comes with Lubuntu.

If you need to do something with your disks, then just click the Disks icon in the panel. You select the disk and Power Off from the top menu.

This is same as handy as 'Safely remove hardware' in Windows OS, and the above positions it more or less in same place as the Windows has it in desktop.

  • Thanks you! I'll certainly will try to use your solution. – Nicholas V. Apr 2 '17 at 14:07

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.