|
|
#1 |
|
Major Leaguer
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 280
|
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
__________________
~Jayson <www.kempinger.us> |
|
|
|
|
|
#2 |
|
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?
|
|
|
|
|
|
#3 |
|
Major Leaguer
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 280
|
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 03:40 PM. Reason: Added thought |
|
|
|
|
|
#4 |
|
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.
|
|
|
|
|
|
#5 |
|
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!
|
|
|
|
#6 |
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,263
|
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- |
|
|
|
|
|
#7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Major Leaguer
Join Date: Feb 2004
Location: Lincoln, NE
Posts: 280
|
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!
The script has two modes:
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> |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,263
|
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- |
|||||||||||||||||||||||
|
|
|
![]() |
|
|