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


Click here to return to the 'Rev. 6.5 International Version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Rev. 6.5 International Version
Authored by: Nimitz on May 15, '06 06:25:25AM
Of course, we silly Europeans use the comma as a decimal placeholder, so all the scripts won't work unless adapted as below. Is there anyone who knows where to get this info (now it is hardwired in a property) out of the System settings (Preference pane International)? This is still the weakest point of Applescript (and Apple): Internationalization.

property decimaldelimiter : ","

on run {}
	-- Initalize variables 
	set trashcontents to {}
	set trashamount to 0
	set itemstoskip to 0
	-- Grab a list of trash contents for each user 
	set thepath to path to current user folder
	
	try -- See if the trashfolder exists 
		set theResult to my GetTrashContents((thepath as string) 
			& ".Trash" as alias, trashamount)
		if (item 1 of theResult is not {}) then
			set end of trashcontents to "** User " & (do shell script "whoami") & "'s Trash Contents **" as string
			set itemstoskip to itemstoskip + 2
			set trashcontents to trashcontents & item 1 of theResult
			set trashamount to (item 2 of theResult) -- supercede new value 
		end if
	end try
	--Grab a list of trash contents for each volume mounted 
	set list_volumes to list disks
	repeat with thevolume in list_volumes
		try
			set theResult to my GetTrashContents(thevolume & 
				":.Trashes:" & (do shell script "echo $UID") as alias, trashamount)
			if ((item 1 of theResult is not {}) and (item 1 of theResult is not {space})) then
				set end of trashcontents to "** Volume " & thevolume & 
					"'s Trash Contents **" as string
				set itemstoskip to itemstoskip + 2
				set trashcontents to trashcontents & item 1 of theResult
				set trashamount to (item 2 of theResult) -- increment trashamount by theamount 
			end if
		end try
	end repeat
	-- Filter the list & format amount 
	if {trashamount = 0} then
		display dialog "Trash currently contains no items" buttons 
			{"Ok"} default button 1
		return false
	end if
	set amount to my FormatSize(trashamount) -- Format trashamount 
	set filteredlist to my FilterList(trashcontents)
	set filtercount to (count of filteredlist) --Count of items in filteredlist 
	set filecount to ((count of trashcontents) - itemstoskip) --Count of items in thefiles 
	set thebutton to ""
	-- Show user the information gathered 
	set theResult to choose from list trashcontents with prompt 
		"There are " & filecount & " files" & " in the trash totaling " & amount & return & return 
		& "Empty Trash?" OK button name "Cancel" cancel button name 
		"Ok" with empty selection allowed
	try
		if (not theResult) then
			tell application "Finder" to empty trash
			if thebutton = false then
			end if
		end if
	end try
end run

on FilterList(thelist)
	set filteredlist to {} -- Holds the files that with "." 
	-- Build the list of files 
	repeat with thefile in thelist
		set olddelim to AppleScript's text item delimiters
		set AppleScript's text item delimiters to " - "
		set thename to every text item of thefile as string
		try
			set thename to text item 2 of thefile
			if (thename begins with ".") then
				set end of filteredlist to thename as string
			end if
		end try
		set AppleScript's text item delimiters to olddelim
	end repeat
	return filteredlist
end FilterList

on FormatSize(thesize)
	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 decimaldelimiter
		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 FormatSize

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
	return thesize
end GetSize

on GetTrashContents(thetrashpath, trashamount)
	set filelist to {}
	-- Get the contents of the trash 
	set thefiles to list folder thetrashpath -- Gets the directory contents of of the folder 
	-- Calculate each file size of thetrashpath 
	repeat with i from 1 to (count of thefiles)
		set thealias to ((thetrashpath as string) & item i of thefiles) as alias 
			--Make the type of file to an alias 
		set theinfo to info for thealias --Get the info on the alias 
		set theamount to my GetSize(thealias)
		set trashamount to trashamount + theamount
		set theamount to my FormatSize(theamount)
		set end of filelist to theamount & " - " & name of theinfo as string
	end repeat
	set end of filelist to space
	return {filelist, trashamount}
end GetTrashContents

---
-----------
The Nimitz

[ Reply to This | # ]