I know that within Kodi it is possible to unmount hard drives one at a time in the file Manager.
File Manager - Name of Drive - Context Menu - Unmount
I usually have about five or six external hard drives connected at one time so I would like to be able to run a shell script to unmount all the external drives that are connected. That way I can simply run this one script, either via an option on the main menu(using a skin that supports this) or I could keymap this script to a button press on a remote.
Created two scripts, Unmount.All.py and Unmount.All.Sudo.py
Unmount.All.py = umount /media/*
Unmount.All.Sudo = sudo umount /media/*
Tried RunScript(“/home/osmc/scripts/Unmount.All.py”) and RunScript(“/home/osmc/scripts/Unmount.All.Sudo.py”) While Kodi found both of them, they both said “Error Script Failed”
To test that it was actually finding the scripts I changed the path and as expected it did nothing, changing it back to the correct path results in the script error.
Googled and saw something about some scripts being run with XBMC.RunScript(“script location”) but that didn’t work either.
Make sure your script is marked as executable and has a hash bang line to load Python with the correct path.
Also make sure you use the full path to umount in your script. I checked and sudo is not needed.
If you’re not doing anything else in your script you should just run the mount command directly from runscript and make sure you have the full path to umount.
I’ve looked into this a bit further and RunScript() is only used for launching python scripts. To run shell commands directly you should use System.Exec() but I have been unable to get this working for some reason. (And can’t really spend any more time on it)
So I would suggest you go back to a python script to run the unmount command (probably using os.system() in python) and test that your python script works from the command line, once you have a script that works from the command line call it with RunScript() and it should work. In theory.
[quote=“DBMandrake, post:14, topic:4564, full:true”]
I’ve looked into this a bit further and RunScript() is only used for launching python scripts. To run shell commands directly you should use System.Exec() but I have been unable to get this working for some reason. (And can’t really spend any more time on it)[/quote]
That is totally understandable. I am sure there must be more pressing issues with the OSMC release at the moment but thanks for taking the time to try to help me out.
I actually thought it would be a quick thing since I had used the RunScript within a Windows environment and it was pretty easy to use but I am new to Linux.
It is more of a Kodi thing anyway so I’ll just post a topic on that forum and see if anyone can help me be lazier which was my only goal with this
I was trying to do the same thing, I don’t know if OP finally got it, but I’ll post it if anyone arrives here looking for the answer (like I did).
I created a Python script that only contains
from subprocess import call
call(["sudo", "umount", "/mnt/your_disk"])
then you just have to call it from the Menu Builder with
[quote=“e_viesca, post:16, topic:4564, full:true”]I created a Python script that only contains
from subprocess import call
call(["sudo", "umount", "/mnt/your_disk"])
[/quote]
I tried this and it does nothing? Doesn’t give me the script error like before but it still doesn’t remove the drives. Have you got it to work and does it matter how many drives you have connected?
Sorry, I only had one drive and I was mounting manually to /mnt so I put the path directly to it. My Pi is unusable at the moment so I can’t try anything right know, if your drives are mounting to /media you could try to put an asterisk as wildcard in the command, it would be something like this:
from subprocess import call
call(["sudo", "umount", "/media/*"])
Will remove the drive, just like using the context menu it will also brings up a notification to say the drive has been successfully removed.
Pretty sure I can just get it to repeat the process for each drive if the wildcard expression doesn’t work but haven’t had a chance to test it yet. Will update this post once I have got it working.
For the wild card to work the command has to be run in a shell as the shell does the wildcard expansion. Check the docs for the Python subprocess.call function - there is an option to run in a shell I believe.