Size of “.Trashes” Folder on external Drive

Hi everyone,

As i’m new to the Forum i want to introduce myself real quick. My Friends call me Neyghey, i’m a Video Editor and Multimedia Artist by profession, heavy Mac user both personally and professionally, and an automation fanatic.
I have used this site as a resource for some time now and thought i’d register for an opportunity to have my own questions answered and also to - maybe one day - give something back to the community. I really appreciate all of your efforts in helping people with their applescript problems, you have helped me dozens of times already as a guest user. So thanks for that! Here’s my first Question:

I’m trying to determine the size of the .Trashes folder of an external Drive. I am working in Automator with a “Run AppleScript" Action that receives an alias to an external Volume as input:

on run {input, parameters}
 	
 	set trashPath to (the POSIX path of input) & ".Trashes"
 	
 	set docFolder to path to documents folder
 	
 	set itemSize to size of (get info for docFolder) --is working
 	
 	--set itemSize to size of (get info for trashPath) --is NOT working
 	
 	display alert itemSize
 	
 	return itemSize
end run

Now, when i run the code like this, i get the correct size of the documents folder in bytes. But when i enable the line where i set itemSize to the size of my .Trashes folder, itemSize is “msng”. I am guessing that i somehow don’t have permission to view the contents of .Trashes?. How would you guys approach this?

I would be very thankful for any insight…:slight_smile:

path to documents folder

is an alias specifier

and

(the POSIX path of input) & ".Trashes"

is a POSIX path. info for expects an alias. Further input is a list

You have to flatten the list and create an alias for example

set trashPath to  ((item 1 of input) as text & ".Trashes") as alias

Thanks Stefan, sadly the result is still “msng”… any ideas? my new code:

on run {input, parameters}
		
	set trashPath to (((item 1 of input) as text) & ".Trashes") as alias
		
	set itemSize to size of (get info for trashPath) --is NOT working
	
	display alert itemSize
	
	return itemSize
	
end run

Hi KniazidisR and thanks for your input!

Sadly the result is still “msng”… I tried both to select the volume and the .Trashes Folder on it…

Thanks for checking! It works for me too on the home directories trash but not on the .Trashes folder of an external drive…

If you look at the infos for the folder .Trashes with cmd I you will see that it’s a Write Only item.

If you want to look in it you must change the privileges to Read & Write.

Take care to reset the initial privileges when you have finish.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 28 avril 2019 21:51:34

Thank you Yvan,

Thats what i was thinking, that it is a privileges issue… Do you mean, i can set the privileges in code, and if yes, how would i do that in applescript? Setting it manually via the finder is not an option for me, sadly… maybe with a run shell script action in automator instead of run applescript?

The other option i have in mind would be to determine the size of all the (unhidden) folders on the drive, add the available space and subtract from the total capacity of the drive, which should give me the (approximate) size of data in the trash.

I am just wondering, if there is a more elegant way to do it…

Thanks for the suggestion, KniazidisR, but .Trashes seems to be a folder… when i run choose file instead of choose folder, i can not choose the .Trashes folder…

Here, my boot volume is an external SSD named “SSD 500”.
I ran this script:

--set myVol to path to startup disk

tell application "System Events"
	set volNames to name of disks whose local volume is true
	--> {"SSD 500", "Macintosh HD"}
	
end tell
set theSizes to {}

set volName to item 1 of volNames

set POSIXPath2Trashes to POSIX path of (volName & ":.Trashes")
set quotedPOSIXPath2Trashes to quoted form of POSIXPath2Trashes
try # MOVED
	do shell script "chmod 775 " & quotedPOSIXPath2Trashes # Standard privileges
	tell application "System Events"
		with timeout of 10000 seconds # ADDED
			set sizeOfTrashes to size of disk item POSIXPath2Trashes
		end timeout # ADDED
	end tell
	set end of theSizes to {volName, sizeOfTrashes}
	
	do shell script "chmod 333 " & quotedPOSIXPath2Trashes # Write Only privileges
end try # MOVED
set volNames to rest of volNames

repeat with volName in volNames
	set volName to contents of volName
	set POSIXPath2Trashes to POSIX path of (volName & ":.Trashes")
	set quotedPOSIXPath2Trashes to quoted form of POSIXPath2Trashes
	try # MOVED
		do shell script "chmod 775 " & quotedPOSIXPath2Trashes with administrator privileges # Standard privileges
		tell application "System Events"
			with timeout of 10000 seconds # ADDED
				set sizeOfTrashes to size of disk item POSIXPath2Trashes
			end timeout # ADDED
		end tell
		set end of theSizes to {volName, sizeOfTrashes}
		
		do shell script "chmod 333 " & quotedPOSIXPath2Trashes with administrator privileges # Write Only privileges
	end try # MOVED
end repeat

theSizes
--> {{"SSD 500", 0}, {"Macintosh HD", 422714353}}

I checked that the value returned for “SSD 500” is OK by running:

tell application "System Events"
	set volName to name of startup disk
end tell

set path2Trashes to volName & ":.Trashes"
set POSIXPath2Trashes to POSIX path of path2Trashes
set quotedPOSIXPath2Trashes to quoted form of POSIXPath2Trashes
do shell script "chmod 775 " & quotedPOSIXPath2Trashes # Standard privileges

tell application "Finder"
	open folder path2Trashes
end tell

display dialog "Check the content of the folder then click a button to reset original privileges"

do shell script "chmod 333 " & quotedPOSIXPath2Trashes # Write Only privileges

Of course, my folder is really empty.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 avril 2019 15:42:55

Added a couple try / end try useful if a .Trashes folder isn’t available on one disk.

Added with timeout of 10000 seconds statements to take care of your huge folder. I hope that the 10000 value would be sufficient.

Moved the try instructions.

Wow Yvan, thanks for going through such lengths to help me…!

Two problems with your code:

  1. when i run it, i have to enter my user PW
  2. when i enter the user PW, i get the following error:

Syntax Error
chmod: /private/var/vm/.Trashes: No such file or directory

i am checking the value of quotedPOSIXPath2Trashes before the error, it is ‘/Volumes/FF_ext_003/.Trashes’ (FF_ext_003 being the external drive i want to check)

why the path later appears to be /private/var/vm/.Trashes is beyond me…

No need to waste more time trying to help me, i have found a “Workaround” that is good enough for me:

on run {input, parameters}
	set oneBreak to "
"
	set allItemsSize to 0
	tell application "Finder"
		
		set fl to items of folder input as alias list
		repeat with theItem in fl
			set theItemSize to size of (get info for theItem)
			set allItemsSize to allItemsSize + theItemSize
			end repeat
		set diskName to name of (get info for input)
		set totalSpace to the (capacity of disk diskName)
		set free_bytes to free space of disk input
		set actuallyAvailable to totalSpace - allItemsSize -- this is free Space plus trash Space (in Theory)
		set actuallyAvailableGB to round (actuallyAvailable / 1.0E+9) rounding down
		activate
		display alert diskName & oneBreak & oneBreak & actuallyAvailableGB
		
	end tell
	
end run

This does not give me the size of the .Trashes Folder, but the Size of ALL hidden Items on the Drive. But it is OK for me, since there should not be a great amount of hidden Space other than in the .Trashes folder…

I really appreciate all of your Input! Thanks again to all of you :slight_smile:

I really don’t understand. I connected a Firewire mechanical HD to my machine.
The result was :
{{“SSD 500”, 0}, {“Macintosh HD”, 422714353}, {“Hitachi 2To1”, 0}}

Of course, I was asked for the passWord to be able to treat the volumes which aren’t the startup one.

The instructions were:


do shell script "chmod 775 '/.Trashes'" # for startup disk
do shell script "chmod 333 '/.Trashes'" # for startup disk
do shell script "chmod 775 '/Volumes/Macintosh HD/.Trashes'" with administrator privileges # asked for passWord
do shell script "chmod 333 '/Volumes/Macintosh HD/.Trashes'" with administrator privileges
do shell script "chmod 775 '/Volumes/Hitachi 2To1/.Trashes'" with administrator privileges
do shell script "chmod 333 '/Volumes/Hitachi 2To1/.Trashes'" with administrator privileges

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 avril 2019 18:16:16

I’m naive and assume that Apple’s engineers have some good reasons to define such privileges for the .Trashes folder.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 avril 2019 18:23:39

Thanks for your suggestion, i think i’m naive as well though, like Yvan, and would prefer not to meddle with apples intended privileges system as long as it can be avoided…

Out of interest, i checked your code again, this time in Script editor. But please, as i said, it is really not important for me anymore, as my workaround works fine for me and i do not have to meddle with privileges or enter a PW.
I check volNames, right after you define it in the second Line: it returns {“Macintosh HD”, “vm”, “TM_BU_5K”, “FF_ext_003”, “FF_ext_034”, “FF_ext_027”, “FF_ext_022”, “Macintosh HD”, “Macintosh HD”}

then i set volName to item 4 of volNames. This are the only two changes i made…

at the line

do shell script "chmod 775 " & quotedPOSIXPath2Trashes with administrator privileges # Standard privileges

i get the error i mentioned above…

May you post the value of quotedPOSIXPath2Trashes and the result of

tell application "System Events"
	properties of disk "FF_ext_003"
end tell
(*
Supposed to return something like:
{container:disk id "FF_ext_003,-101,2" of application "System Events", path:"FF_ext_003:", capacity:9.99345127424E+11, volume:"FF_ext_003", physical size:missing value, URL:"file:///Volumes/FF_ext_003", id:"FF_ext_003,-101,2", displayed name:"FF_ext_003", zone:missing value, ignore privileges:false, busy status:false, name:"FF_ext_003", name extension:"", free space:1.99129010176E+11, POSIX path:"/Volumes/FF_ext_003", startup:false, modification date:date "mardi 26 mars 2019 à  10:07:42", local volume:true, size:missing value, format:Mac OS Extended format, class:disk, package folder:false, creation date:date "dimanche 19 août 2012 à  20:07:17", visible:true, ejectable:false, server:missing value}
*)

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 30 avril 2019 13:57:34

the Value of quotedPOSIXPath2Trashes is ‘/Volumes/FF_ext_003/.Trashes’

properties of disk FF_ext_003 is:

{container:disk id “FF_ext_003,-110,2” of application “System Events”, path:“FF_ext_003:”, capacity:3.000144142336E+12, volume:“FF_ext_003”, physical size:missing value, URL:“file:///Volumes/FF_ext_003”, id:“FF_ext_003,-110,2”, displayed name:“FF_ext_003”, zone:missing value, ignore privileges:true, busy status:false, name:“FF_ext_003”, name extension:“”, free space:4.8226091008E+11, POSIX path:“/Volumes/FF_ext_003”, startup:false, modification date:date “Monday, 29. April 2019 at 17:16:34”, local volume:true, size:missing value, format:Mac OS Extended format, class:disk, package folder:false, creation date:date “Thursday, 16. January 2014 at 17:09:40”, visible:true, ejectable:false, server:missing value}

Thanks!

Thanks.

Have you checked that the folder really exists ?
If it doesn’t, the error is logical.
It would be useful to add a couple try / end try in the code.
I will edit the message with the script accordingly.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 30 avril 2019 16:33:53

Thank you Yvan,

Your altered code computes without error, i changed volName to item 4 of volNames again, my result:

{{“FF_ext_003”, -1.846161564E+9}, {“TM_BU_5K”, 0}, {“FF_ext_003”, -1.846161564E+9}, {“FF_ext_034”, 0}, {“FF_ext_027”, 0}, {“FF_ext_022”, 0}, {“Macintosh HD”, 0}, {“Macintosh HD”, 0}}

should the second value be the size of Trashes in bytes? Because as a test, i have a 190 GB file in .Trashes on FF_ext_003. 1.846161564E+9 bytes equal 1.84 GB (also, the value seems to be negative)

any ideas whats going on?

I never guessed that you have a so huge folder.
To calculate the value of this size, System Events requires a lot of time and when the standard limit ( 2 minutes) allowed to execute a task is reached what you get is the value grabbed from the previous disk
To get the full value I added a “with timeout of 10000 seconds” statement in the script available in my “old” message.

It would be useful to make a bit of cleaning because these Gigabytes are just wasted.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 2 mai 2019 15:58:20