Weird Finder problem

Hi,

I’ve written some code but there is a problem with it. It’s designed to determine the space available on a usb device. It works but only a bit. The output is just like I need so that’s fine. The problem is that it returns an error the first time I run is after mounting the volume. The second time, and any time after that, everything is fine. The error is: “-1700: can’t make missing variable into type real”.


	tell application "Finder"
		set theDisk to disk theDevice
		set theFolder to MusicPath as alias
		set dCapacity to (capacity of theDisk) / 1024 / 1024
		set dSize to (size of disk theDisk) / 1024 / 1024
		set fSize to (size of folder theFolder) / 1024 / 1024
		set PlayerCapacity to dCapacity - (dSize - fSize)
	end tell

The error is about line 6: set fSize…

Who gets this or can help me in any way?

Hi,

you coerced the path to theFolder to an alias,
leave it as a string and it works
(Also theDisk is already a “disk”, there is no need to use disk theDisk)

tell application "Finder"
	set theDisk to disk theDevice
	set theFolder to MusicPath -- as string eventually
	set dCapacity to (capacity of theDisk) / 1024 / 1024
	set dSize to (size of theDisk) / 1024 / 1024
	set fSize to (size of folder theFolder) / 1024 / 1024
	set PlayerCapacity to dCapacity - (dSize - fSize)
end tell

Thanks for the quick reply but it doesn’t work for me. Like I said, the output is the way it should be. But it’s only okay the second time I run the script. The first time the script returns a missing value. I just don’t get why, whatever I do it won’t work the first time.

I guess, it takes some time to calculate the size.
Maybe it’s useful to use a little loop and an error handler

tell application "Finder"
	set theDisk to disk theDevice
	set theFolder to MusicPath as alias -- as string eventually
	set dCapacity to (capacity of theDisk) / 1024 / 1024
	set dSize to (size of theDisk) / 1024 / 1024
	repeat
		try
			set fSize to (size of folder theFolder) / 1024 / 1024
			exit repeat
		on error
			delay 0.5
		end try
	end repeat
	set PlayerCapacity to dCapacity - (dSize - fSize)
end tell

Thanks, that works well.