Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm using this line to get the size of a folder:

set thesize to physical size of folder x

The problem is that sometimes it works, other times it doesn't, and it's very annoying because there doesn't seem to be any kind of logic to it. The same folder path can return "missing value" at first, then return the number of bytes later, without any code change. It seems to start working more often after I "Get Info" on the folder in the Finder, but even that doesn't always work.

How do you make this reliable? I can't send my application to other people with this kind of unpredictability on my own computer.

share|improve this question
add comment

2 Answers 2

Try Automator. I did it and it worked for me on each folder. I tried it as a Service.

I might have automator actions that you don't have.

You can get them here if that's the case:

http://www.automatedworkflows.com

There you will find awesome automator action packs. Very useful.

Phil

share|improve this answer
add comment

As you precisely describe, this is happening because it takes time to gather that information. If the operation times out before the system calculates the size, you'll get the error. When you use "Get Info" beforehand it caches the result.

share|improve this answer
    
I put that piece of code inside a try—end-try statement and that inside a repeat statement with many iterations, and it still didn't work. So it's not just a matter of giving the system time to obtain the information. I ended up using do shell script "du -ms " & quoted form of (POSIX path of thefile) & " | cut -f 1" –  hawk Mar 14 '13 at 11:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.