UNIX path variables like $HOME don’t work in AppleScript,
there is the path to command to specify well-known folders
For example the alias to the pictures folder is
set x to path to pictures folder
to retrieve the size of the trash folder you can use this,
it considers that the Finder takes some time to calculate the size
tell application "Finder"
repeat until size of trash is not missing value
delay 0.2
end repeat
display dialog (get size of trash as text)
end tell
That is not working OMM running Snow Leopard. I get missing value for any folder I try.
I get the same thing when using physical size. Not sure what is up with that.
How is this for a shell command?
set thePath to quoted form of POSIX path of (path to pictures folder)
do shell script "du -sh " & thePath & " | awk '{print $1}'"
#Or for the trash
do shell script "du -sh ~/.Trash | awk '{print $1}'"
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 "Trash contains " & number_of_items & " items, which use " & trash_size & " of disk space. Do 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
almost everything after the display dialog line is not necessary.
display dialog aborts the script automatically if the user presses the Cancel button
and the Finder tell block is defined at the beginning
set trash_size to (do shell script "du -h ~/.Trash | tail -rn1 | awk '{print \"\" $1}'")
tell application "Finder"
set number_of_items to (count every item of the trash)
activate
display dialog "Trash contains " & number_of_items & " items, which use " & trash_size & " of disk space. Do you want to delete these items?" with icon stop buttons {"Cancel", "Empty Trash"} default button 2
empty
end tell