Jump to content

Control my cdrom tray


Recommended Posts

hi guys .. I've got an idea but my bash/sh skills are lacking so ...

 

here's a run down of what I want the code to be like

 

firstly a file called

~/.cdromstatus

closed

 

secondly the code bit

this is NOT real code ... because I suck at writing bash scripts ... but maybe someone will understand what I am trying to achieve

#!/bin/bash
STATUS = file(~/.cdromstatus)

if $STATUS == closed {
   $COMMAND = "eject /dev/cdrom"
   rm ~/.cdromstatus
   echo open > ~/.cdromstatus
}

if $STATUS == open {
   $COMMAND = eject -t /dev/cdrom"
   rm ~/.cdromstatus
   echo closed > ~/.cdromstatus
}

exec $COMMAND

 

understand what am trying to do?

Link to comment
Share on other sites

ok figured how to do it myself ;)

#!/usr/bin/php -q
<?php
$status_file = "/home/paul/.cdtray_status";
$cd_status = file($status_file);
$cd_status = rtrim($cd_status[0]);

$device = "/dev/cdrom";

function update_status($status, $status_file) {
       $out = fopen($status_file, "w");
       fwrite($out, $status);
       fclose($out);
}

switch ($cd_status) {
       case "closed":
               update_status("open", $status_file);
               $command = "eject ".$device;
               break;
       case "open":
               update_status("closed", $status_file);
               $command = "eject -t ".$device;
               break;
       default:
               $command = "xmessage \"can't get cdrom status\"";
}

exec($command);
?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...