Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to make a script that ejects all connected external drives and does not move on until they are all disconnected.

The main problem I'm having is being able to set the variable vol_count to the result of the following script:

tell application "Terminal"
    cd /Volumes
    ls | wc -l
end tell

I also have not tested that script, but I assume that's how you run a terminal command from within an applescript.

Follow up question:

How would I then have it eject all but two disks (my hard drive is partitioned into two disks)?

on run {}

    tell application "Finder"
        set vol_count to do shell script "cd /Volumes; ls | wc -l"

        eject the disks

        repeat until vol_count is equal to 2
            set vol_count to do shell script "cd /Volumes; ls | wc -l"
        end repeat
    end tell
end run
share|improve this question

3 Answers 3

up vote 2 down vote accepted

try:

set dontEject to {"Mac OS X", "Time Machine", "Media", "home", "net"}
set myDisks to list disks

repeat with aDisk in myDisks
    if aDisk is not in dontEject then tell application "Finder" to eject aDisk
end repeat
share|improve this answer
    
This is the best answer. –  CajunLuke Jan 10 '13 at 19:08
    
Wow, thanks! That's perfect! –  JShoe Jan 10 '13 at 19:51

That is not how you run a terminal command in AppleScript. Try something like

set myvar to do shell script "ls ~"
share|improve this answer

You can do something like this:

set vol_count to do shell script "cd /Volumes; ls | wc -l"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.