can apple script open the cd tray?

Discussion in 'Macintosh Computers' started by bennetsaysargh, Mar 15, 2004.

  1. bennetsaysargh macrumors 68020

    bennetsaysargh

    Joined:
    Jan 20, 2003
    Location:
    New York
    #1
    if it can, how would you put that into applescript?

    thanks :)
     
  2. sageenos macrumors member

    Joined:
    Jan 5, 2002
    Location:
    South Carolina
    #2
    I just tried it myself, but I can only get it to work for a specific CD in the tray

    tell application "Finder"
    eject "CDName"
    end tell

    I'm not sure how to eject any CD or to just cause the tray to open
     
  3. BrandonRP0123 macrumors regular

    Joined:
    Jul 28, 2003
    Location:
    San Francisco, CA
    #3
    Not sure how to do it with Apple Script to ``eject all''

    You can do it with a unix shell script, however.

    You'll need to figure out what disk # your CD/DVD unit is.

    Then you could create a script via your favorite unix shell that has in it something like (for my powerbook):

    disktool -e disk1 (or you could just execute this yourself by typing it in on the terminal command line)

    This method will work when the eject menu and/or key combinations fail as well.
     
  4. bennetsaysargh thread starter macrumors 68020

    bennetsaysargh

    Joined:
    Jan 20, 2003
    Location:
    New York
    #4
    how do i find out what disk # my cd/dvd drive is?
     
  5. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #5
    Well, if you can do it with the Terminal, you can do it using AppleScript using the Terminal. ;)

    Code:
    
    tell application "Terminal"
    	activate
    	do script "disktool -e disk1"
            quit
    end tell
    
    Of course, if you keep the Terminal application open, remove the line with "quit" in it.
     
  6. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #6
    That works fine as long as something is in the drive. It reports the following:

    disk2s1s2 device will attempt to be ejected ...
    ***Notifications Complete for type 1
    ***Responding yes to unmount - disk2s1s2
    ***Disk Unmounted('disk2s1s2')
    ***Disk Unmounted('disk2')
    ***Notifications Complete for type 4
    ***Responding yes to eject - disk2
    ***Responding yes to eject - disk2s1
    ***Responding yes to eject - disk2s1s1
    ***Responding yes to eject - disk2s1s2
    ***Disk Ejected('disk2')
    ***Disk Ejected('disk2s1s2')
     
  7. OutThere macrumors 603

    OutThere

    Joined:
    Dec 19, 2002
    Location:
    NYC
    #7
    If you don't want to have the terminal come up to do the script then you can do this...

    Code:
    do shell script "disktool -e disk1"
    
    Or you can get really hard-core applescripter and use the "disktool" terminal command to get the list of disks, then tell you what disks there are, and allow you to select from a list the disk you want, and have it ejected, but you might have to spend some time reading the Applescript Studio docs, I don't have time to help you with that right now. Cheers!
     
  8. tjwett macrumors 68000

    tjwett

    Joined:
    May 6, 2002
    Location:
    Brooklyn, NYC
    #8
    in Terminal this command is probably the easiest:

    drutil tray eject

    that's it. of course you could easily have AppleScript tell the Terminal to run this as you normally would.
     
  9. bennetsaysargh thread starter macrumors 68020

    bennetsaysargh

    Joined:
    Jan 20, 2003
    Location:
    New York
    #9
    hey, thanks everyone :)
    Code:
    do shell script "drutil tray eject"
    do shell script "drutil tray close"
    that's what i am using. is there any way you can make applescript wait a few seconds? i ask this because if you ask it to repeat, it starts closing, but opens back up.

    thanks again :)
     
  10. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #10
    Of course there is. :D
     
  11. bennetsaysargh thread starter macrumors 68020

    bennetsaysargh

    Joined:
    Jan 20, 2003
    Location:
    New York
    #11
    do you know how? :p

    edit-also, does anyone know if you can make something force quit in applescript?
     
  12. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #12
    I'm going to have to get you a link to the information or buy you a book. :p

    delay 10

    to delay for 10 seconds

    You can use the kill shell script command if you know information about the job you want to force quit.
     
  13. bennetsaysargh thread starter macrumors 68020

    bennetsaysargh

    Joined:
    Jan 20, 2003
    Location:
    New York
    #13
    thanks bousozoku. i really appreciate the help :)
     
  14. yippy macrumors 68020

    yippy

    Joined:
    Mar 14, 2004
    Location:
    Chicago, IL
    #14
    hey, i want to do the same thing but when i put

    do shell script "drutil tray eject"

    into applescript and hit run i get an error, it says

    sh: drutil: command not found

    any help? i am running 10.2.8 if that matters on applescript beta 2.0 and the tcsh shell or whatever it is called in terminal

    thanks
     
  15. Sweetfeld28 macrumors 65816

    Sweetfeld28

    Joined:
    Feb 10, 2003
    Location:
    Buckeye Country, O-H
    #15
    If you don't mind me asking what mac are you using? If you are using an old world mac (ADB-- keyboard and mouse) then i think that by pressing the F12 key it opens the cd tray, the master drive that is. but, i'm sure that you knew this. :D
     
  16. tjwett macrumors 68000

    tjwett

    Joined:
    May 6, 2002
    Location:
    Brooklyn, NYC
    #16
    take a look at the manual page for drutil. i don't think it is included in OS 10.2.x perhaps you can download it somewhere though. i should have said that earlier, sorry. this works in Panther only, unless you install it yourself in 10.2.x
     

Share This Page