1

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.

0

2 Answers 2

1

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.

1
  • This isn't the correct method though. It won't work if any of those names change, like say with an OS update. Jun 8, 2015 at 22:46
0
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
5
  • Those AppleScript one-liners are quite something. Jun 7, 2015 at 13:28
  • I get an error notification: number -1728 from 1 to «class furl»
    – user121028
    Jun 7, 2015 at 14:42
  • I'm getting a very long result. Should I post it?
    – user121028
    Jun 8, 2015 at 16:22
  • With the new script I get as result "MobileBackups" - Thanks :)
    – user121028
    Jun 10, 2015 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. Jun 10, 2015 at 18:11

You must log in to answer this question.

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