I want to remove a part of an AppleScript result. The part of my whole code is following

list disks

I get the result: {"Macintosh HD", "MobileBackups", "home", "net", "USB-Stick"} How can I remove the part "Macintosh HD", "MobileBackups", "home", "net", so that only volumes that are not the whole time available are shown.


Try something like this:

set mydisks to list disks
set newdisks to {} as list
repeat with currentdisk in mydisks
    if ((currentdisk as string) is not equal to "net") and ((currentdisk as string) is not equal to "home") and ((currentdisk as string) is not equal to "Macintosh HD") and ((currentdisk as string) is not equal to "MobileBackups") then
        set newdisks to newdisks & currentdisk
    end if
end repeat

You will have your desired list on newdisks.

| improve this answer | |
  • This isn't the correct method though. It won't work if any of those names change, like say with an OS update. – William T Froggard Jun 8 '15 at 22:46
tell application "Finder" to set disklist to every disk whose ejectable is true or local volume is false and name is not "home" and name is not "net"
set namelist to {}
repeat with diskitem in disklist
    set end of namelist to name of diskitem
end repeat
return namelist
| improve this answer | |
  • Those AppleScript one-liners are quite something. – William T Froggard Jun 7 '15 at 13:28
  • I get an error notification: number -1728 from 1 to «class furl» – user121028 Jun 7 '15 at 14:42
  • I'm getting a very long result. Should I post it? – user121028 Jun 8 '15 at 16:22
  • With the new script I get as result "MobileBackups" - Thanks :) – user121028 Jun 10 '15 at 12:25
  • @user121028: Ok, I admit I was wrong several times. I think this one may actually work. I define "not the whole time available" to means either plugged into a USB port or connected through the internet. – David Anderson Jun 10 '15 at 18:11

You must log in to answer this question.

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