osx - Eject all disks and dmg's with Automator script in Mac OS X

06
2014-04
  • swis24

    I have created an Automator Service to eject all disks in Mac OS X.

    find /dev -name "disk[1-9]" -exec diskutil eject {} \;
    

    This works, but I still receive an error message afterwords:

    "The action “Run Shell Script” encountered an error."

    Anyone know why this is happening?

  • Answers
  • user3936

    When I run the command, I get errors about files in /dev/fd:

    $ find /dev -name "disk[1-9]" -exec diskutil eject {} \;
    find: /dev/fd/3: Not a directory
    find: /dev/fd/8: Not a directory
    

    You don't need find though:

    diskutil eject /dev/disk[1-9];exit 0
    

    exit 0 makes the script exit without an error if /dev/disk[1-9] doesn't match any file.

    You might also use a Run AppleScript action like this:

    tell app "Finder" to eject disks
    

  • Related Question

    osx - Ruby script step in Mac Automator workflow does not exit
  • Mark Robinson

    I have created an Automator workflow in Mac OS X 10.5.8. The workflow is supposed to run a Ruby script and then shutdown the computer.

    The Ruby script copies files between several computers and then sends an email when complete. When I run the script in Automator all code is executed with out errors, because I get the email and all the files are copied, but the Automator step running the script never exits so the computer never shuts down. I have tested the shutdown step independently and it works fine.

    The Ruby script takes around 20 minutes to complete. If I cut the script down so it just sends the email and executes in less then 10 seconds, the Automator workflow executes all the way and the computer shuts down.

    enter image description here

    Any ideas?


  • Related Answers
  • Mark Robinson

    Added exit function to the end of the ruby script. Now the shell script step finishes correctly in Automator and then runs the AppleScript to shutdown the computer.