Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

?gruebel?

macrumors newbie
Original poster
Aug 3, 2014
6
0
Hi all

Is there a way to list all unmounted disks/volumes with AppleScript?

Thanks for your help.
?gruebel?
 
This should do the trick.

Code:
do shell script "diskutil list"


Thanks, it works so far. But how to go from there . . .

p.ex.
Code:
set all to do shell script "diskutil list"
set one to choose from list (result)

gives
/dev/disk0

How can I get the name of the disk/partition and how can I mount it?

Thanks a lot for your help. I'm eager to learn.
 
Here is a script that will mount/unmount all external drives

oh well
 
Last edited:
Thanks a lot for the input

Interesting scripts, food for brain.
But I don't want to have all disks mounted/unmounted.
I prefer to have a list presented to choose the one I want to mount or unmount (without having to pre-difine all my disks in the script).
I don't know if that's possible. - I haven't found any hint in the man page for mount/unmount that you can show/list unmounted disks.
OSX disk utility shows unmounted disks - but unfortunatley it's not an scriptable app.

Anyway, thanks and greetings. :)
 
Possible with Objective-C/Cocoa

I prefer to have a list presented to choose the one I want to mount or unmount (without having to pre-difine all my disks in the script).
I don't know if that's possible.

If you can write a little Objective-C it isn't that difficult to call Disk Utility and parse its output ( possibly starting with parsing based on CR( carriage return ) using either CFStringCreateArrayBySeparatingStrings() or its similar Cocoa NSString componentsSeparatedByString: ) and put it in a tableview. Disk Utility could be called with a pipe or using a Cocoa NSTask. Disk Utility identifies all the volumes but AFAICT doesn't distinguish unmounted from mounted. That would take additional code. btw: since you apparently are looking for an Applescript solution, I didn't post code.
 
Last edited:
That would take additional code. btw: since you apparently are looking for an Applescript solution, I didn't post code.

Another approach: use Apple's DiskArbitration calls for volume information. ( i.e. #import <DiskArbitration/DiskArbitration.h> ) and register for the NSWorkspace notificationCenter. Process the notifications you are interested in using NSWorkspaceDidRenameVolumeNotification, NSWorkspaceDidMountNotification, NSWorkspaceWillUnmountNotification and NSWorkspaceDidUnmountNotification and update the tableview accordingly.

Here is a link for DiskArbitration code: https://stackoverflow.com/questions/11633425/get-a-list-of-unmountable-drives-using-cocoa. You would need to retrieve different keys from the dictionary ( descDict ) as shown in this code but the basic approach is right. HTH.
 
Hello briloronmacrumo

Thank you for your effort. Your tips are a bit over my level of knowledge. But I'll to follow your hint.
 
That's the way I'm doing it now . . .

Code:
--- unmount - mount partitions
set all to paragraphs of (do shell script "ls /Volumes")
set w to choose from list all with prompt "wich one?" cancel button name "or activate?" OK button name "go away" with multiple selections allowed
try
	repeat with teil in w
		do shell script "diskutil unmount `diskutil list | awk '/ " & teil & "  / {print $NF}'`"
	end repeat
end try

if w = false then --- if you press "or activate?"
	
	set Part to display dialog "name it!" default answer " " buttons {"none", "this one"} default button 2
	set this to text returned of Part
	set butn to button returned of Part
	if butn = "none" then error number -128 --- Cancel
	if butn = "this one" then
		try
			repeat with wakeup in this
				do shell script "diskutil mount `diskutil list | awk '/ " & this & " / {print $NF}'`"
			end repeat
		end try
	end if
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.