*nix tray CD Tray Opener

Selfbondage software and other kinky developments

Moderators: Riddle, Shannon SteelSlave

Post Reply
not1975
*
Posts: 11
Joined: 06 Sep 2010, 02:27

*nix tray CD Tray Opener

Post by not1975 »

Hello everyone. Been following this forum a bit for while. I noticed that there is a CD tray opening program availible for Windows, but not for other operating systems. On both Mac and Linux the "eject" command opens a CD tray. Here is a simple script I've thrown together that works on Linux and should work on all Unix based operating systems:

Code: Select all

if [ $# -ne 2 ];
then
    echo "Input two integers: minutes and seconds of countdown time"
    exit
elif [ $1 -lt 0 -o $2 -lt 0 ];
then
    echo "Invalid integer value"
else
    
MIN=$1
SEC=$2

while [ $MIN -ge 0 ]; do
    
    while [ $SEC -ge 0 ];do
        echo Countdown  $MIN minutes and $SEC seconds
        let SEC=SEC-1
        sleep 1
    done
    
    let MIN=MIN-1
    let SEC=59
done

eject

fi

You can test the effect of the eject command beforehand, or you can change the "eject" to anything else based on your specifics. Basically just copy this to a text file, then chmod +x the file in the command line so you can run it as a script, and then type the file path (starting with a forward slash) to run it.
User avatar
LoKiT
Retired Moderator
Posts: 372
Joined: 12 Apr 2010, 01:07

Re: *nix tray CD Tray Opener

Post by LoKiT »

8) Kool, that works great. Nice one

Had to tweak the 'eject' command as I more than one eject able device, like a 2 CD's and a tape streamer. Should anyone get stuck on that one type 'eject --help' and you can then adjust the command line in the script to suit.
Anne
*
Posts: 2
Joined: 20 Sep 2010, 08:32

Re: *nix tray CD Tray Opener

Post by Anne »

Hey,

I just wanted to add that I wrote a similar script that I use on my laptop, I posted it on an other forum some while ago.

Link

The idea is to use a laptop because it is battery powered. My script tests every 5 seconds if the laptop is running on battery, if this is the case it releases immediately. My idea was that a power failure is unexpected and not a good thing, not to mention getting stuck if the battery runs out before the timer does :D

Code: Select all

!/bin/bash

DRIVE='/dev/sr0' #Change this to the location of your drive

read -p "How many minutes before release? : " TIME
echo "Starting timer: $TIME minutes"

TIMESEC=`expr $TIME \* 60`
NLOOPS=`expr $TIMESEC / 5` #loop every 5 seconds

i=0
while [ $i -le $NLOOPS ]
do
  #check if we still have mains power
  STATUS=`acpi | grep Discharging | wc -l`
  if test $STATUS -gt 0
  then
    echo "Laptop is running on battery, releasing now..."
    eject -T $DRIVE
    exit 1
  fi
  #wait 5 secs
  sleep 5;
  i=$(( i+1 ))
  echo "`expr $TIMESEC - 5 \* $i` seconds to go..."
done

echo "Time is up, releasing..."
eject -T $DRIVE
exit 0
Of course test it before using it, as mentioned by LoKiT you must change /dev/sr0 in te script to whatever drive you want to release.

I only use this for short sessions (15 minutes or so) but I did not build in any limit, check what you have typed before hitting enter.
Post Reply