jarmen

Q: Eject audio disc when finished burning

As a follow up to my previous post, using Applescript I'm selecting some audio files in the Finder, importing them into iTunes, then burning a CD in one pass. I've tried adding, using Automator, a shell script at the end to eject the tray using

 

do shell script "drutil tray eject"

 

 

but the problem is the action wants to happen before the CD is finished burning and iTunes returns a no cd present error. Can anyone suggests a method to let the first action finish or a check to make sure there is a cd with data present before attempting to eject?

 

Tried below. No luck.

 

jamac 2016-04-04 at 9.38.22 AM.jpg

OS X Mavericks (10.9)

Posted on Apr 4, 2016 7:42 AM

Close

Q: Eject audio disc when finished burning

  • All replies
  • Helpful answers

  • by Camelot,

    Camelot Camelot Apr 4, 2016 10:31 AM in response to jarmen
    Level 8 (47,233 points)
    Mac OS X
    Apr 4, 2016 10:31 AM in response to jarmen

    There doesn't appear to be anything in iTunes dictionary related to the state of burning CDs, so there's no direct way to detect when it's finished.

     

    It's been a while since I've burned a disk, but your best bet may be an indirect approach - does iTunes post a dialog/window showing the burn progress? If that's the case you could add a loop inside your initial script to detect when this window disappears - something like:

     

      set doneBurning to false

      repeat until doneBurning

      if not (exists window "Burning CD") then -- change the name to whatever is actually used

      set doneBurning to true

      end if

      delay 5 -- wait a bit before checking again...

      end repeat


    It's crude, but it should work.

  • by jarmen,

    jarmen jarmen Apr 4, 2016 11:25 AM in response to Camelot
    Level 1 (4 points)
    Mac OS X
    Apr 4, 2016 11:25 AM in response to Camelot

    Thanks Camelot. It doesn't actually popup a burning window, but does it within the initial window with a dialog (see screenshot). I did notice that upon inserting a blank CD, nothing is mounted on the Desktop, but after the burn, the disc is mounted on the Desktop. Could the Finder be focused or checked in a loop until the disc is mounted, then ejected at that point?

    burning.jpg

  • by Jacques Rioux,Solvedanswer

    Jacques Rioux Jacques Rioux Apr 4, 2016 7:41 PM in response to jarmen
    Level 4 (3,408 points)
    Mac OS X
    Apr 4, 2016 7:41 PM in response to jarmen

    Hi,

     

    You can use the "drutil status" command to get the information, like this:

     

    The bash script:

    #### wait until the burning begins
    until $(drutil status | grep -q "Media Is Busy");do
        sleep 5
    done
    
    #### now, wait until the CD is finished burning
    while $(drutil status | grep -q "Media Is Busy");do
        sleep 5
    done
    
    drutil tray eject ### eject the CD