Erase or format a disk or volume by applescript??

I’d like to have an applescript to erase or format a disk or volume (in this case CompactFlash cards -connected through a firewire cardreader- that all have the name “EOS_DIGITAL”), but Googling my way thru the web I can’t find any hints on how to do it. Should be possible, don’t you think? Anyone?


Model: G3 iBook, G5 PowerMac
Browser: Safari 312
Operating System: Mac OS X (10.3.9)

My first thought would be:

tell application "Finder"
 erase disk "EOS_DIGITAL"
end tell

But I haven’t tried it for obvious reasons :slight_smile:

do shell script “rm -rf /Volumes/EOS_DIGITAL/*”

would hopeuflly work.

Thank you Reikon, your suggestion works flawlessly! Camelot, yours didn’t :frowning: but thanks for your trouble anyway.


doesn’t work if volume contains folders

Oh yes it does! do shell script “rm -rf /Volumes/EOS_DIGITAL/*” works as it should, including subfolders.

don’t get angry, am not being sarcastic, tried it 3x yesterday, didn’t work, maybe i missed something, will try again later today, will post results afterwards. am trying to delete the contents of my flash drive.

other than deleting the contents, can the volume be formatted via applescript?

I’m not angry - sorry if I seemed that way!

Can you delete (sub)folders and files manually from your Mac? If not, they may have gotten some kind of ‘protection’ from your camera.

I would also really appreciate a script to format a disk…

it really doesn’t work mate, it can’t delete subfolders, is it because the memory stick / flash drive is windows formatted?

NAh, my CompactFlash cards are also formatted in FAT16 (in-camera). You are using a cardreader I assume, not connecting your camera directly to your Mac?? And, did you try to manually delete files and (sub)folders from the finder??

The described method workes for me on Jaguar and Tiger. Copy everything below between <<< and >>> and paste that into scripteditor.

do shell script “rm -rf /Volumes/EOS_DIGITAL/*”

I tried it again this morning with a freshly installed tiger, it works, i wonder what went wrong with my panther. it donesn’t have anything to do with file permissions.

here’s a batch script to erase zip disks i just wrote after searching for a good way to erase disks. not perfect or too elegant but it works nicely. save as a stay open script.

set tcont to "Continue"
repeat until tcont is not "Continue"
	set treply to ""
	tell application "Finder"
		set tdisks to every disk whose size < 1.005E+8 and size > 100
		if (count tdisks) = 1 then
			set tdisk to item 1 of tdisks
			set tpath to quoted form of (POSIX path of (tdisk as alias))
			set tname to name of tdisk
			set treply to button returned of (display dialog "Erase " & tname & "?" buttons {"No", "Yes"} default button "Yes")
		end if
	end tell
	if treply is "Yes" and (count tdisks) = 1 then
		do shell script ("rm -rf " & tpath & "*") with administrator privileges
		tell application "Finder"
			set name of tdisk to "Zip100"
				eject tdisk
			on error
				set tdisks to every disk whose name is "Zip100"
				if (count tdisks) = 1 then eject (item 1 of tdisks)
			end try
		end tell
	end if
	tell application "Finder"
		set tcont to button returned of (display dialog "Please insert a new disk and then click continue, or quit." buttons {"Quit", "Continue"} default button "Continue")
	end tell
end repeat

i think something like:

do shell script "/usr/sbin/diskutil   reformat /Volumes/EOS_DIGITAL"

would erase the drive for you.

NOTE: caveat scripter! i have no way to test this. i’m not sure that diskutil can do ‘FAT 16’.

see ‘man diskutil’ for more options.