How to open *and* close a drive by a keybinding

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

How to open *and* close a drive by a keybinding

Post by hoppel »

Hi,


I'm trying to set up a keybinding for ejecting and closing my dvd-drive. Since all I could discover as a point-and-click solution was a keybinding for just opening the drive I searched the web and found hints on the following website:
http://ubuntuforums.org/archive/index.php/t-660515.html
But, although I followed the instructions carefully, all I achieved by using this script:

Code: Select all

#./bin/bash

tray_status=`cat .tray_status.sh`
if [ "$tray_status" == "Closed" ]
then
eject /dev/hdc
echo "Open" > .tray_status.sh
elif [ "$tray_status" == "Open" ]
then
eject -t /dev/hdc
echo "Closed" > .tray_status.sh
else
eject
echo "Open" > .tray_status.sh
fi

...was a global keybinding which also only opened the drive but couldn't close it. Maybe someone knows what I did wrong? What I want: open & close the drive with one command, like Ctrl+Escape.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

Hi,

in fact there is no problem if I use "eject -t /dev/hdc" in terminal - the tray closes then. I'll try the other solutions later, now I'm under Windows...
But I already used "chmod 755 /home/(your home)/tray_status.sh" on that script... And the script is in my home directory, there shouldn't be problems with write permissions there...?
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

Well,

using 'cat .tray_status.sh' answered 'open' or 'closed' just as it should be. I discovered one fault I made with the script - I created it with root privileges, so the access was restricted. Though changing this unfortunately didn't do anything about the problem...
But when I enter the tray_status.sh in a shell it opens and closes - that's strange, don't you think?
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

Could you please explain me the last part again?
and change the executing to:

Code: Select all
/home/user/tray_script 2> tray.log > tray.log
Where exactly do I have to alter this?
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

I followed the instructions I found here: http://ubuntuforums.org/archive/index.php/t-660515.html:

Code: Select all

We'll show you how to use only one key to open & shut your drive (thanks for the script Rhubarb!!! His post: http://ubuntuforums.org/showthread.php?t=656674 )

First we need to know if you only have one drive or more than one....

If you only have one:

Open Text Editor & paste the following:

#./bin/bash

tray_status=`cat .tray_status.sh`
if [ "$tray_status" == "Closed" ]
then
eject
echo "Open" > .tray_status.sh
elif [ "$tray_status" == "Open" ]
then
eject -t
echo "Closed" > .tray_status.sh
else
eject
echo "Open" > .tray_status.sh
fi

Save the file to your /home as tray_status.sh (note that it matches the info in the script!!!)

Next open a terminal & chmod 755 /home/(your home)/tray_status.sh

chmod 755--The user has read, write and execute permissions; the group and others can only read and execute.
That is the safest way to set permissions on the file.

Next, open up Configuration Editor. I have found that you can't bind this command to F12 (not sure, will need to do more checking).

So we are going to bind the command to F11. I chose command_10, you can use command_1 & modify the rest of the keybinding to match your choice.

In any case, the command should be /home/(your home)/tray_status.sh
Next we'll move to the global_keybindings. Under run_command_10, I used the the F11 key.
I nearly did it that way. In Configuration Editor I changed the key '/apps/metacity/global_keybindings/run_command_1' to '<Control>o' and '/apps/metacity/keybindings_commands/command_1' to '/home/username/tray_status.sh'
Now '<Control>o' opens the drive but does not close it, although the script entered in a shell opens and closes it.

Oh, and by the way: By trying to solve this problem a new error ocured. During the start process a message is displayed, that the file '.dmrc' has incorrect privileges (should be 644). And Amule doesn't start anymore. This is all very strange and I cannot guarantee, that there is really a connection between these problems, but I haven't done anything else deep in the system...

To be honest, I'm really looking forward to the next update of Mint, so that I can redo everything....
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

Ok, I replaced the line in configuration editor with it, but tray.log remains empty.

But one thing I figured out myself: There is something wrong in the process status written into .tray_status.sh.
To make it easier for me to understand I shortened tray_status.sh to this code:

Code: Select all

#./bin/bash

tray_status=`cat $HOME/.tray_status.sh`
if [ "$HOME/.tray_status" == "Closed" ]
then
eject /dev/hdc
echo "Open" > $HOME/.tray_status.sh

else
eject -t /dev/hdc
echo "Closed" > $HOME/.tray_status.sh
fi
This should also work, am I right? The reaction to this lines is an noticeable attempt of the drive to close - it doesn't matter whether it is already closed or not (it blinks and makes a short noise if it is already closed). And in .tray_status.sh it says 'Closed' all the time. When I enter 'Open' manually it just changes to 'Closed' without the drive doing anything...
hoppel
Level 3
Level 3
Posts: 174
Joined: Wed Oct 10, 2007 1:38 pm

Re: How to open *and* close a drive by a keybinding

Post by hoppel »

Well,


if, then elif and else doesn't seem to work correctly - the status written to 'tray_status.sh' is always the last one in the script...
Locked

Return to “Other topics”