Is It Possible to Have a Shortcut Button Assigned to Eject USB HDD?

Hi. Does anyone know if it’s possible to assign a shortcut button to eject the USB HDD attached to Vero 4K? :):grin:

Would like this too. Suppose could map a button to a script to run an unmount command.

1 Like

It’s literally 4 button presses to do this. How much time is this realistically going to save you?
Settings > File Manager > Open context menu on HDD > Remove Safely.

How do I make a script for that? :smiley:

I usually turn off my TV when not in use.
Then, times when I want to just unplug the HDD, I still need to turn on my TV (which takes about a good 10 seconds) then do the thing you mentioned. Simply put, I don’t want to have to turn on my TV everytime I need to unplug the HDD. Hope this explains things better.

Then SSH into the system from a PC or even a phone and issue an umount command for the HDD.
sudo umount /path/to/HDD
Mine for eg would be sudo umount /media/EXTHDD1

I don’t really find that more convenient than pressing a button.

  1. I don’t keep my PC on all the time.
  2. I don’t like installing unnecessary things on my phone.
    and since I keep my Vero 4K always on, I’d rather grab the remote and press a button and wait for about 3 seconds and just unplug the HDD :slight_smile:

Then you will need to make the unmount command into a script, make it executable and then set a remote command in the remote.xml file to run that script.
Here is a link to a very old thread but the same principles should apply Gotham run shell script via keyboard shortcut?
If you want something more up to date just google for run script in kodi via keyboard press

Thanks for sharing the link. Unfortunately, it’s all Greek to me. It might be easy for you to do, but not for me. I’ll just make this into a feature request and hope people would find it a useful feature.

I will test with a script tonight and let you know if it works. I’ll give you instructions how to do it then

2 Likes

Thank you! :grin:
Is it also possible to assign it to a long-press? Like if I press and hold the home button for 3 seconds?

Hi eager

Sorry for late reply just tested mapping a button to script and works well unmounting drive. Works with longpress too. An an extra step i also mapped a button to remount an ejected drive again.

Ok here are steps:

  1. Download the winscp program and install it on your pc WinSCP :: Official Site :: Download

  2. Open winscp. Select new site. Fill in the details as follows
    File Protocol: SCP
    Host Name: Enter ip address of your vero
    Port Number: 22
    Username & Password: If you haven’t changed the username or password before then it osmc for both

    Click on advanced. Select scp/shell on left hand side column. In shell dropdown menu change from default to sudo su -.
    Warning: I recommend you change this back to default after you have finished this tutorial as you are able to delete system files with this enabled.

    Click ok and select save. Tick the remember passoword box. Click login.

  3. Next download putty program here and install Download PuTTY: latest release (0.74)

Open putty. Put in vero ip address in host name and click open. Enter vero username and password when prompted.

  1. Run command blkid. You should see line like /dev/sda1 or sdb1. If you have 1 hard drive attached this is your hard drive.

  2. Next open notepad and paste the following into it. Change the sda1 if yours is different.

#!/bin/sh

sudo umount /dev/sda1
exit

  1. Save the file as Unmount.sh to desktop.
    Make sure you dont save as a text file. Select all files from the drop down menu when saving

  2. Go back to winscp. On left hand column navigate to your desktop. On the right navigate to your osmc folder /home/osmc/

  3. Drag and drop the Unmount.sh file over from desktop to osmc

  4. Right click on Unmount.sh select properties. And tick all the R,W,X boxes. Click ok.

  5. Next navigate to folder /home/osmc/.kodi/userdata/keymaps

  6. Next double click on the keyboard.xml or gen.xml file.

  7. Add your key you want to map the key too like the following. I used f1 key but you can choose any key instead just replace f1.

        <keymap>
         <global>
          <keyboard>
              <f1 mod="longpress">System.Exec(/home/osmc/UnmountDrive.sh)</f1>
           </keyboard>
          </global>
          </keymap>
    

Note: If you are using a remote instead of a keyboard you may need to install the keymap editor addon in the kodi repo and run it and map something to the button you want to use to get the right key id. When keymap editor is saved. Open the xml file in /home/osmc/.kodi/userdata/keymaps. There should be a line similar to < key id=“61531”> where the id is your button id. So replace the f1 line above to something like

< key id=“61531” mod=“longpress”>System.Exec(/home/osmc/MountDrive.sh)< /key>

  1. Save xml and go back to putty and run the command

Sudo systemctl restart mediacenter

Hopefully now when you hold down your button the hard drive removal message should pop up.

Hope this helps :slight_smile:

4 Likes

Thanks, the_bo! You rock! I’ll try this out :smiley:

Alternative if all automatically mounted drives should be unmounted you can use a search as part of your script awk '$2 ~ "^/media/" { print $2 }' /proc/mounts

2 Likes

You read my mind. Thank you!

Hi,

Thanks for writing this detailed guide, which is REALLY helpful for someone who is not familiar with Linux system file management, like me. I don’t understand why such a functionnality is not provided by Kodi commands, or any plugin, or added through to the OSMC layer.

I have created the Unmount.sh file as described, then I added the following action to a custom shortcut action definition (Settings / Interface / Skin setup / Customize Home Menu):

System.Exec(/home/osmc/Unmount.sh)

Unfortunately the first time I use the shortcut from Home menu it doesn’t work, and the second time it makes OSMC crash and reboot.

Any help or idea would be appreciated.
Thanks in advance.

Hello,

Here is my auto-answer in case someone is interrested in having a menu shortcut to disconnect the Vero-4K external drive safely:

  • On Windows create a “Unmount.py” file with the following text content:

    from subprocess import call
    call([“udisks”, “–unmount”, “/dev/sda1”])

  • Install WinSCP and connect to the Vero. This post tells how to:
    Is It Possible to Have a Shortcut Button Assigned to Eject USB HDD? - #12 by the_bo

  • Copy the file to “/home/userscripts” (or wherever you want)

  • On the Vero-4K go to “Settings / Interface / Skin setup / Customize Home Menu” and add a shortcut where needed. Personnaly I want it in the sub-menu (left key) of the “Files” menu item.

  • Define Name : “Disconnect Drive”

  • Define Action with the following custom command:

    RunScript("/home/userscripts/Unmount.py")

That’s it.

I have also added a “Connect Drive” shortcut with the same method : call([“udisks”, “–mount”, “/dev/sda1”]). But I guess someone will want a single script that connects or disconnects depending on the current status.

I wonder why the functionnality is not provided by Kodi or at least facilitated by an Addon.