Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Erase CD-Rs with an AppleScript System
One of my pet peeves about Mac OS X is that there is no easy way to erase CDRWs. One either has to use the Terminal to call 'hdiutil burn -erase' or use Disk Utility, which is counterintuitive and could simply be considered dangerous.

To avert these problems, I wrote a quick and dirty AppleScript to allow regular users to erase CDRWs. The script is simple and straightforward (mainly due to my lack of AppleScript experience), but it does provide a relatively simple, safe way to erase rewritable discs.

Read the rest of the article for the script.

(*
Erase ReWritable Media
2002 Nathan Teske
Calls'hdiutil burn -erase' to erase rewritable media¬
without the terminal or Disk Utility
*)

beep
display dialog "Erase a rewritable disc?" buttons {"Cancel", "Yes"}¬
default button "Cancel" with icon note
set the user_choice to the button returned of the result
if the user_choice is "Yes" then

display dialog "Are you sure you want to erase a disc?" & return & return & ¬
"You cannot undo this action." buttons {"Cancel", "OK"} default button "Cancel" with icon alert
set the user_choice to the button returned of the result

if the user_choice is "OK" then
display dialog "Press OK and insert your disc. It may take several minutes to erase your disc."
do shell script "hdiutil burn -erase"
display dialog "Your disc has been erased." buttons {"•"} default button 1 giving up after 10
end if

end if
[Editor's note: I have not tried this script myself.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[12,103 views]  

Erase CD-Rs with an AppleScript | 6 comments | Create New Account
Click here to return to the 'Erase CD-Rs with an AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Format Disk
Authored by: achterberg on May 23, '02 11:23:15PM

Works fine for erasing a disk, I got rid of the extra "are you sure" dialog, because it annoys me. Does anyone know how to do the next step and format the CD with Applescript?



[ Reply to This | # ]
erase CD script fails
Authored by: osxpounder on Jun 04, '02 02:42:36PM

When I try to run this script, I get a pop up box, titled "Execution Error", that reports: "The variable alert is not defined."

The word "alert" in this box is highlighted in a different color.



[ Reply to This | # ]
re: erase CD script fails
Authored by: osxpounder on Jun 04, '02 02:47:23PM

I find that if I remove the words "with icon alert", though, that the script seems to work .... testing now. It reportedly erased my CD, and OSX recognized the CD as blank when I reinserted, so .... so far, so good.

Thanks for this great script!



[ Reply to This | # ]
Aqua Guidelines!!!!!!
Authored by: Morgoth on Sep 24, '02 09:27:28PM

Just cause I'm that kind of person I'm going to complain about stupid details.

The "Yes/Cancel" is a Windows thing to do. Apple always uses actions as the labels for its buttons. I rewrote it to have "Erase CD-RW/Cancel" and put the "This action is not reversible" warning as the description text in the dialog.

By the way, that script is an excellent idea. I keep forgetting about AppleScript.



[ Reply to This | # ]
Confirmation is not necessary
Authored by: logo on Jan 10, '03 07:36:11AM

The way hdiutil burn -erase works would not need a confirmation.

Whenever you start it with a disk in the drive it will be ejected.
Then, if you insert whatever CDRW in the now open drive, it will be erased right away, no question asked. So at this point you should be aware of what you're doing anyway!!!

However what I would like to do is to display a window that stays open during the whole process that says "Erasing..."

Can this be done with plain AppleScript, or do I need AppleScript Studio or an extension?

Thanks for the Hint and hopefully a suggestion!!!

Peter



[ Reply to This | # ]
Erase CD-Rs with an AppleScript
Authored by: skydiverx on Dec 15, '04 04:08:28PM
The following script is a modified version of the previous script. It has been tested with 10.3.6 and it works.

Many thanks to Nathan Teske for the original script.

Enjoy.

-SkyDiverX



(*
Erase ReWritable Media
2002 Nathan Teske
Calls'hdiutil burn -erase' to erase rewritable media¬
  without the terminal or Disk Utility
  
Modified by Efren Palacios for AAS use
on Dec 14, 2004
*)

beep
display dialog "Erase a rewritable disc?" buttons {"Cancel", "Yes"} ¬
	default button "Cancel" with icon note
set the user_choice to the button returned of the result
if the user_choice is "Yes" then
	
	display dialog "Are you sure you want to erase a disc?" & return & return & ¬
		"You cannot undo this action." buttons {"Cancel", "OK"} default button "Cancel"
	set the user_choice to the button returned of the result
	
	if the user_choice is "OK" then
		display dialog "It may take several minutes to erase the disc." & return & return & ¬
			"After the disc is erased, a Finder dialog box will appear asking you to name your CD. This will be your indication that the erase process has finished." & return & return & ¬
			"You will NOT get a progress window after you start this process." & return & return & ¬
			"Insert your disc and press ERASE." buttons {"Cancel", "ERASE"} ¬
			default button "Cancel"
		set the user_choice to the button returned of the result
		
		do shell script "hdiutil burn -erase"
		
	end if
end if



[ Reply to This | # ]