Go Back   The macosxhints Forums > OS X Help Requests > Applications



Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 04-24-2005, 08:51 PM   #1
GlowingApple
Major Leaguer
 
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 278
Mini-hint: Shred files with an Applescript droplet

Since my discovery of the wonder of OS X I have had a gripe about the way the Finder handles files with the Trash. In Windows I would frequently delete a file permanently without ever putting it in the trash. Occasionally I like to delete files but leave them in the trash for a time until I'm absolutely sure I want to permanently get rid of them, but then later find a file that I want to delete immediately to save disk space without emptying the trash.

Take this for an example. I just e-mail a set of pictures to a friend and then trash the folder to keep my Desktop organized, but I don't want to empty the trash just yet. I want to wait until I hear back from my friend to ensure that he/she successfully received the pictures. Later I finish burning a CD of my favorite Linux distro, (Gentoo), and I want to delete the iso image to save space on my hard drive. Without doing a little fancy terminal work there is no easy way to permanently delete the file without emptying my trash and also permanently deleting those pictures.

This is where my script comes into play. The following is Applescript meant for a dropplet (so save in an application bundle). Dragging and dropping files onto it will prompt first and then permanently shred the files (using `rm -rfP`). Just to add more functionality to the script, I added an option to shred all the files in the trash by opening the application regularly.

Code:
(*
Author: Jayson Kempinger
E-mail: evilglowingapple@gmail.com
Date created: 23 April 2005

Permantly Shred script
Drop files/folders onto this as an application.  This script will shred the files
using the command specified in property command.

Icon modified from origional e.shred.gif at http://www.lebofsky.com/write/hailstorms.html
*)

--command to shred files.  Use shred if you have it installed, use "rm -rfP " if you do not
property command : "rm -rfP "

--when running the app not as a dropplet, shred the files in the current user's trash
on run
	set x to display dialog "Do you want to permanently shred (delete by overwriting) all the files in your trash?" buttons {"Yes", "No"} default button "No"
	if button returned of x is "Yes" then
		try
			do shell script command & "~/.Trash/*"
		end try
		--update trash icon in the dock
		tell application "Finder" to update trash
	end if
end run

--shred dropped files
on open of target_files
	--combine filenames of all files into one string for subject
	set n to 1
	set filenames to ""
	set filelist to {return}
	repeat until n is the ((length of target_files) + 1)
		set n_file to item n of target_files
		if n is less than (length of target_files) then
			--set filenames for command and filelist for dialog prompt
			set filenames to filenames & "\"" & POSIX path of n_file & "\"  "
			set filelist to filelist & POSIX path of n_file & {return}
		else
			--set filenames for command and filelist for dialog prompt
			set filenames to filenames & "\"" & POSIX path of n_file & "\""
			set filelist to filelist & POSIX path of n_file
		end if
		set n to n + 1
	end repeat
	
	set x to display dialog "Do you want to permanently shred (delete by overwriting):" & filelist & "?" buttons {"Yes", "No"} default button "No"
	if button returned of x is "Yes" then
		try
			do shell script command & filenames
		end try
		--update trash icon in the dock just in case files were from the trash folder
		tell application "Finder" to update trash
	end if
end open
Also, attached is the entire thing in an application bundle, with icon. As always, suggestions, comments, and modifications are welcome!
Attached Files
File Type: zip Permanently Shred.zip (29.7 KB, 2986 views)
__________________
~Jayson <www.kempinger.us>
GlowingApple is offline   Reply With Quote
Old 04-25-2005, 01:10 PM   #2
giskard22
Moderator
 
Join Date: May 2003
Posts: 4,272
Semi-random semi-related question: does the Finder's "Secure Empty Trash" option do the same thing as rm -P, or does it use srm, or something totally different? Anyone know?
giskard22 is offline   Reply With Quote
Old 04-25-2005, 01:17 PM   #3
GlowingApple
Major Leaguer
 
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 278
No, the Finder's secure delete is actually more secure as it uses close to a true government wipe. I found the information about the rm -P option (I never knew it existed up until I started writing this script) from here: http://www.mcelhearn.com/chapter5.pdf. However, for what I am using this script for I figured the rm -P option is good enough and easiest to script for individual files. Plus the rm -P command seems to be a fair bit quicker than Finder's secure delete.
__________________
~Jayson <www.kempinger.us>

Last edited by GlowingApple; 04-25-2005 at 02:40 PM. Reason: Added thought
GlowingApple is offline   Reply With Quote
Old 04-29-2005, 06:13 PM   #4
RobLewis
Prospect
 
Join Date: Nov 2004
Posts: 5
UI suggestion

Don't know if it's possible, but it would be really nice if you could Option-Drag files to the droplet and it would bypass the confirmation dialog.
RobLewis is offline   Reply With Quote
Old 03-08-2010, 11:37 PM   #5
Hello.
Guest
 
Posts: n/a
Sorry! But I don't really understand how this works. I download the application down and accidentally pressed yes and got all my files in the trash deleted. I guess I can let that slide, but I don't want that happening again. So can you please tell me the instruction in the MOST simplest form? THANKS!
  Reply With Quote
Old 03-09-2010, 11:55 PM   #6
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
I wrote a script a while back for securely deleting selected files using srm, and posted it on MacScripter.net - you can see it here. I just run it from the script menu at need, but it could easily be adapted to other uses.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 05-03-2010, 12:33 PM   #7
GlowingApple
Major Leaguer
 
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 278
Quote:
Originally Posted by RobLewis
Don't know if it's possible, but it would be really nice if you could Option-Drag files to the droplet and it would bypass the confirmation dialog.

That's a good idea. I don't know of any way to do this with Applescript, but provided I find time in the future, I'll have to dig into some Cocoa and it should be trivial to do there. If you would rather never have the prompt, you can always remove the dialog and the check in the script, but accidental drags could be problematic!


Quote:
Originally Posted by Hello.
Sorry! But I don't really understand how this works. I download the application down and accidentally pressed yes and got all my files in the trash deleted. I guess I can let that slide, but I don't want that happening again. So can you please tell me the instruction in the MOST simplest form? THANKS!

The script has two modes:
  1. If you drag and drop a file or folder onto the application icon, it will permanently "shred" that file. It does this by deleting the file and then writing over the hard drive data several times with "blank" data to ensure a secure delete.
  2. If you run the application just by double-clicking it, it will instead "shred" all files and folders in the trash.
Be careful though, there is practically no way to recover a file once you've "shredded" it with this program! Also, although I had tested this extensively on my own computer when I wrote the script (and did not run into any problems), I can't guarantee 100% that nothing can go wrong ... so use at your own risk!


Quote:
Originally Posted by tw
I wrote a script a while back for securely deleting selected files using srm, and posted it on MacScripter.net - you can see it here. I just run it from the script menu at need, but it could easily be adapted to other uses.

Looks like our scripts are pretty similar. I hadn't heard about the srm command before, but it looks like it's more secure than using rm -P. I wonder if there's any significant speed decrease by using more wipes.
__________________
~Jayson <www.kempinger.us>
GlowingApple is offline   Reply With Quote
Old 05-03-2010, 12:55 PM   #8
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
Quote:
Originally Posted by GlowingApple
Looks like our scripts are pretty similar. I hadn't heard about the srm command before, but it looks like it's more secure than using rm -P. I wonder if there's any significant speed decrease by using more wipes.

well, since it's at the unix level, the time is probably proportional to the number of wipes (i.e. 7 wipes will take a little more than twice as long as 3 wipes). but since it runs as a background process, it shouldn't be very noticeable to the user (not like the Finder secure delete, which ties up the GUI in unpleasant ways).
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:16 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.