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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...