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


Click here to return to the 'Selectively shred files with an Applescript droplet' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Selectively shred files with an Applescript droplet
Authored by: Krioni on Apr 29, '05 03:12:33PM
There are some areas your script could be improved. For example, in your code you have:

   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

Rather than putting your own quotes around the posix path, you could use the Apple-supplied method: quoted form of, and end up with:


		if n is less than (length of target_files) then
			--set filenames for command and filelist for dialog prompt
			set filenames to filenames & quoted form of POSIX path of n_file & space
			set filelist to filelist & POSIX path of n_file & {return}
		else
			--set filenames for command and filelist for dialog prompt
			set filenames to filenames & quoted form of POSIX path of n_file
			set filelist to filelist & POSIX path of n_file
		end if

Also, I'm not sure why you used "on open of targetFiles" - "on open targetFiles" is the correct way to use "on open". Another change is that you can loop over the items in a list, without needing an iteration variable. This means you can do:


	repeat with n_file in target_files
...etc...
Something else to keep in mind is that the variable 'filenames' isn't really a bunch of filenames, its a bunch of file paths. Perhaps naming it filePaths would be clearer? So, here's the script, with some modifications:

(*
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

-- some modifications by Dan Shockley (http://www.danshockley.com)
*)


--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 target_files
	--combine filePaths of all files into one string for subject
	
	set filePaths to "" -- space-separated list of file-paths for the shell command
	set fileVerticalList to "" -- retrn-delimited list of file-paths for dialog prompt
	
	repeat with n_file in target_files
		set n_file to contents of n_file -- sometimes a "reference" is not a good thing, so
		-- let's explicitly set n_file to the 
		
		if length of filePaths is 0 then
			set filePaths to filePaths & quoted form of POSIX path of n_file & space
			set fileVerticalList to fileVerticalList & POSIX path of n_file & return
		else
			set filePaths to filePaths & quoted form of POSIX path of n_file
			set fileVerticalList to fileVerticalList & POSIX path of n_file
		end if
	end repeat
	
	set x to display dialog "Do you want to permanently shred (delete by overwriting):" & return & fileVerticalList & "?" buttons {"Yes", "No"} default button "No"
	if button returned of x is "Yes" then
		try
			do shell script command & filePaths
		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


[ Reply to This | # ]