1

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
3

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
2

You can do something like this:

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

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

set myvar to do shell script "ls ~"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .