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


Click here to return to the 'Display the size of the trash prior to emptying - Major revision 2 to include above requests :D' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display the size of the trash prior to emptying - Major revision 2 to include above requests :D
Authored by: cougar718 on Mar 01, '03 11:50:48PM

Here you go everyone. This targets everything said above. Let me know what everyone thinks. (The View List option sees two buttons, both do the same thing, I could not make it just one button)

on run {}
set thepath to path to trash -- The folder to size up
-- Get the contents of the trash
set thefiles to list folder thepath -- Gets the directory contents of of the folder specified above
set filteredlist to {} -- Holds the files that don't begin with "."
-- Build the list of files
repeat with thefile in thefiles
if (thefile does not start with ".") then
set end of filteredlist to thefile as string
end if
end repeat
set amount to GetSize(thepath) --Get the physcial size of the folder
if (amount = "0 kB") then
display dialog "Trash currently contains no items" buttons {"Ok"} default button 1
return false
end if
set filtercount to count of filteredlist --Count of items in filteredlist
set filecount to count of thefiles --Count of items in thefiles
set thebutton to ""
repeat until thebutton is in {"Yes", "No"}
-- Show user the information gathered
display dialog "There is " & amount & " in the trash. Consists of..." & return
& filecount - filtercount & " invisible(s)" & return
& filtercount & " normal(s)" & return & return
& "Total Files : " & filecount & return & return
& "Would you like to empty the trash?" buttons {"View Files", "No", "Yes"} default button 2
set thebutton to the button returned of result
if thebutton = "Yes" then
tell application "Finder" to empty trash
else if thebutton = "View Files" then
set thelist to my CreateList(thefiles, thepath)
choose from list thelist with prompt "Current Files in the Trash" OK button name "Back" with empty selection allowed
end if
end repeat
end run

on CreateList(thefiles, thepath)
set newlist to {}
repeat with i from 1 to (count of thefiles)
tell application "Finder"
set filepath to ((thepath & item i of thefiles) as string) as alias
set theamount to my GetSize(filepath)
set end of newlist to theamount & " - " & (item i of thefiles) as string
end tell
end repeat
return newlist
end CreateList

on GetSize(thepath)
repeat
try
tell application "Finder" to set thesize to ((physical size of thepath) / 1024)
exit repeat
on error
delay 1
end try
end repeat
if (thesize > 1024) then
set thesize to thesize / 1024 as string
set olddelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set thesize to every text item of thesize
set item 2 of thesize to item 1 of item 2 of thesize
set thesize to thesize as string
set AppleScript's text item delimiters to olddelim
set thesize to thesize & " MB" as string
else
set thesize to (thesize as integer) & " KB" as string
end if
return thesize
end GetSize

---
Rick Bargerhuff alias cougar
Programmer / Developer
Apple Technician / Specialist / Web Designer
Personal Email: cougar718@comcast.net



[ Reply to This | # ]
Display the size of the trash prior to emptying - Major revision 2 to include above requests :D
Authored by: MaxMarino on Mar 02, '03 06:09:52AM

I do not do Applescript (yet?) but shouldn't the line from GetSize()


tell application "Finder" to set thesize to ((physical size of thepath) / 1024)

be instead

tell application "Finder" to set thesize to ((physical size of thepath))

then the subsequent check whether thesize is >1024 is meaningful. Othewise looks to me that you get 0 everytime thesize is less than 1024 (int).

PS

I tried it but it does not see any file in the Trash: always sees Trash as empty.



[ Reply to This | # ]
Display the size of the trash prior to emptying - Major revision 2 to include above requests :D
Authored by: bostmass on Mar 02, '03 08:24:35AM

This is great. Unfortunately, it doesn't tell you if you have anything from another volume or partition. Other than that, it works like a charm.



[ Reply to This | # ]
Display the size of the trash prior to emptying - Major revision 2 to include above requests :D
Authored by: MaxMarino on Mar 02, '03 09:34:18AM

Ahhh, that's it.

I have 4 partitions.



[ Reply to This | # ]