Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Growl notification when new item added to folder qom Mac Programming 1 Jan 8, 2011 12:30 PM
My trash has >8000 items and won't delete? brimky Mac Basics and Help 2 Jun 19, 2010 04:05 PM
Can't Trash Item whiteryno117 Mac Applications and Mac App Store 1 May 17, 2009 08:24 PM
Rogue Trash Item iMacFan78 Mac Basics and Help 2 Nov 25, 2006 09:58 PM
Cant trash items....HELP buryyourbrideau OS X 6 May 2, 2005 02:32 PM


All times are GMT -5. The time now is 11:10 AM.

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

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