Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 17, 2007, 02:10 PM   #1
TheSpaz
Banned
 
Join Date: Jun 2005
Trash Items and Size AppleScript?

I'm trying to make a simple script that tells me the number of items in the Trash and also the Size in MB. Here's a line of code I found online that creates a dialog with the Trash size but, I don't know how to make it display the number of items too.

display dialog (do shell script "du -h ~/.Trash | tail -rn1 | awk '{print \"Size of Trash is \" $1}'")

This script works good but, does anyone care to show me how to add the number of items in the Trash too?
TheSpaz is offline   0 Reply With Quote
Old Jan 17, 2007, 09:50 PM   #2
applelabs
macrumors member
 
Join Date: Jan 2007
Send a message via AIM to applelabs
You need to add:
Code:
set number_of_items to (count (every item of the trash))
For example...

Code:
tell application "Finder"
	set trash_size to (do shell script "du -h ~/.Trash | tail -rn1 | awk '{print \"The size of the Trash is \" $1}'")
	set number_of_items to (count (every item of the trash))
	activate
	display dialog trash_size & return & "The number of items is " & number_of_items & "." with icon stop buttons {"Empty Trash", "OK"} default button 2
	if the button returned of the result is "Empty Trash" then
		tell application "Finder"
			empty trash
		end tell
	end if
end tell

Last edited by applelabs; Jan 17, 2007 at 09:56 PM.
applelabs is offline   0 Reply With Quote
Old Jan 17, 2007, 10:32 PM   #3
TheSpaz
Thread Starter
Banned
 
Join Date: Jun 2005
Quote:
Originally Posted by applelabs View Post
You need to add:
Code:
set number_of_items to (count (every item of the trash))
For example...

Code:
tell application "Finder"
	set trash_size to (do shell script "du -h ~/.Trash | tail -rn1 | awk '{print \"The size of the Trash is \" $1}'")
	set number_of_items to (count (every item of the trash))
	activate
	display dialog trash_size & return & "The number of items is " & number_of_items & "." with icon stop buttons {"Empty Trash", "OK"} default button 2
	if the button returned of the result is "Empty Trash" then
		tell application "Finder"
			empty trash
		end tell
	end if
end tell
THANKS SO MUCH DUDE! Is it okay if I use this code and modify it to my needs. You rock!
TheSpaz is offline   0 Reply With Quote
Old Jan 18, 2007, 08:13 AM   #4
TheSpaz
Thread Starter
Banned
 
Join Date: Jun 2005
Here's what I ended up doing to the script:

Code:
tell application "Finder"
	set trash_size to (do shell script "du -h ~/.Trash | tail -rn1 | awk '{print \"\" $1}'")
	set number_of_items to (count (every item of the trash))
	activate
	display dialog "The Trash contains " & number_of_items & " items, which use " & trash_size & " of disk space. Are you sure you want to delete these items?" with icon stop buttons {"Cancel", "Empty Trash"} default button 2
	if the button returned of the result is "Empty Trash" then
		tell application "Finder"
			empty trash
		end tell
	end if
end tell
Thanks again.
TheSpaz is offline   0 Reply With Quote
Old Jan 18, 2007, 10:08 AM   #5
applelabs
macrumors member
 
Join Date: Jan 2007
Send a message via AIM to applelabs
Quote:
Originally Posted by TheSpaz View Post
THANKS SO MUCH DUDE! Is it okay if I use this code and modify it to my needs. You rock!
Sure. Go crazy with it.
applelabs is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Change "show item info" in Finder icon view to show size of folder instead of items? drought OS X Mavericks (10.9) 2 Jan 17, 2014 11:52 PM
Is there an app that selectively deletes items in the Trash? chrisshewchuk Mac Applications and Mac App Store 6 Jan 10, 2014 06:13 PM
Empty Trash "Unlocked Items"? Macinstache MacBook Pro 5 Nov 19, 2013 01:08 PM
Delete items placed in trash x days ago budsimrin OS X 10.8 Mountain Lion 5 Aug 12, 2013 10:17 PM
Cannot put items in trash from second internal HD. Deletes immediately treadted2 OS X 10.8 Mountain Lion 4 Jan 12, 2013 02:55 PM

Forum Jump

All times are GMT -5. The time now is 04:56 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC