AppleScript Problem Under Snow Leopard
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 116
- Joined: Mon Apr 30, 2007 3:33 pm
AppleScript Problem Under Snow Leopard
Greetings All,
In one of my programs, I use the script below to determine the size of a folder. Under Tiger and Leopard, everything worked great. I did have to run the AppleScript a couple times to get the answer sometimes, but it worked. Under Snow Leopard, the result always comes up as "missing value"
Does anybody know what's going on?
Thanks,
John Miller
-- fileLoc = name of current folder
replace "/" with ":" in fileLoc
put "tell application " & QUOTE & "Finder" & QUOTE into myScript
put CR & "set x to " & QUOTE & fileLoc & QUOTE & " as alias" after myScript
put CR & "get physical size of folder x" after myScript
put CR & "set y to result" after myScript
put CR & "end tell" after myscript
do myScript as appleScript
if the result = "missing value" then
put "tell application " & QUOTE & "Finder" & QUOTE into myScript
put CR & "set x to " & QUOTE & fileLoc & QUOTE & " as alias" after myScript
put CR & "get physical size of folder x" after myScript
put CR & "set y to result" after myScript
put CR & "end tell" after myscript
do myScript as appleScript
end if
put the result into folderSize
In one of my programs, I use the script below to determine the size of a folder. Under Tiger and Leopard, everything worked great. I did have to run the AppleScript a couple times to get the answer sometimes, but it worked. Under Snow Leopard, the result always comes up as "missing value"
Does anybody know what's going on?
Thanks,
John Miller
-- fileLoc = name of current folder
replace "/" with ":" in fileLoc
put "tell application " & QUOTE & "Finder" & QUOTE into myScript
put CR & "set x to " & QUOTE & fileLoc & QUOTE & " as alias" after myScript
put CR & "get physical size of folder x" after myScript
put CR & "set y to result" after myScript
put CR & "end tell" after myscript
do myScript as appleScript
if the result = "missing value" then
put "tell application " & QUOTE & "Finder" & QUOTE into myScript
put CR & "set x to " & QUOTE & fileLoc & QUOTE & " as alias" after myScript
put CR & "get physical size of folder x" after myScript
put CR & "set y to result" after myScript
put CR & "end tell" after myscript
do myScript as appleScript
end if
put the result into folderSize
-
- Posts: 116
- Joined: Mon Apr 30, 2007 3:33 pm
AppleScript Problem Under Snow Leopard
Well,
I've been digging around in AppleScript and have made the following discoveries.
Under Tiger and Leopard "physical size of folder x" returns the size of the entire folder and can be used to determine the size of a volume, folder, or file. To get the size in GB, you have to divide the result by 1024/1024/1024.
Under Snow Leopard, "physical size of folder x" only works with a volume, and now returns the amount of space available instead of the entire capacity. To get the capacity you have to add the "physical size of folder x" + "the free space of folder x". Snow Leopard also changes the way that size is measured. You now have to divide the result by 1000/1000/1000.
Apple changed the way that the finder measures capacity because Hard Drive manufacturers use 1000 gigabits per GB and Apple has always used 1024 gigabits per GB which made it appear as if the hard drive was smaller than the manufacturer stated.
I'll keep digging to see if there is a way to get an actual folder size.
John Miller
I've been digging around in AppleScript and have made the following discoveries.
Under Tiger and Leopard "physical size of folder x" returns the size of the entire folder and can be used to determine the size of a volume, folder, or file. To get the size in GB, you have to divide the result by 1024/1024/1024.
Under Snow Leopard, "physical size of folder x" only works with a volume, and now returns the amount of space available instead of the entire capacity. To get the capacity you have to add the "physical size of folder x" + "the free space of folder x". Snow Leopard also changes the way that size is measured. You now have to divide the result by 1000/1000/1000.
Apple changed the way that the finder measures capacity because Hard Drive manufacturers use 1000 gigabits per GB and Apple has always used 1024 gigabits per GB which made it appear as if the hard drive was smaller than the manufacturer stated.
I'll keep digging to see if there is a way to get an actual folder size.
John Miller
-
- Posts: 116
- Joined: Mon Apr 30, 2007 3:33 pm
AppleScript Problem Under Snow Leopard
Hi! I'm back!!!
To get the size of a folder or file under Snow Leopard use . . .
get (physical size of item x)/1000/1000 which gives the size in MB
x = the path to the folder or file.
Thanks,
John Miller
To get the size of a folder or file under Snow Leopard use . . .
get (physical size of item x)/1000/1000 which gives the size in MB
x = the path to the folder or file.
Thanks,
John Miller
-
- Posts: 116
- Joined: Mon Apr 30, 2007 3:33 pm
AppleScript Problem Under Snow Leopard
One More Time
You can use "(get capacity of folder x)/1000/1000/1000" instead of adding the physical size & the free space.
John
You can use "(get capacity of folder x)/1000/1000/1000" instead of adding the physical size & the free space.
John
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Hello, John!
I still have the same problem as you described even after replaced "folder" by "item":
tell application "Finder"
set x to path2choosen_folder as alias
get physical size of item x
set curent_size_choosen_folder to result
end tell
if the result = "missing value" then
tell application "Finder"
set x to path2choosen_folder as alias
get physical size of item x
set curent_size_choosen_folder to result
end tell
end if
The variable "curent_size_choosen_folder" shows constantly only "missing value"
Did I get you wrong?
Thanks for any hint!
Regards,
Vlad Ghitulescu
I still have the same problem as you described even after replaced "folder" by "item":
tell application "Finder"
set x to path2choosen_folder as alias
get physical size of item x
set curent_size_choosen_folder to result
end tell
if the result = "missing value" then
tell application "Finder"
set x to path2choosen_folder as alias
get physical size of item x
set curent_size_choosen_folder to result
end tell
end if
The variable "curent_size_choosen_folder" shows constantly only "missing value"

Did I get you wrong?
Thanks for any hint!
Regards,
Vlad Ghitulescu
Re: AppleScript Problem Under Snow Leopard
Hi Vlad,
welcome to the forum.
it seems to be a problem of Snow Leopard/Finder scripting
I tried and this seems to work:
of course you have to provide a valid path to the variable path2choosen_folder
Let me know if this works for you.
Kind regards
Bernd
welcome to the forum.
it seems to be a problem of Snow Leopard/Finder scripting
I tried and this seems to work:
Code: Select all
set path2choosen_folder to "aHardDisk:Users:aUser:Desktop:aFolder"
tell application "System Events"
set curent_size_choosen_folder to (physical size of disk item (path2choosen_folder))
end tell
Let me know if this works for you.
Kind regards
Bernd
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Hello, Bernd!
Thanks for the quick reply!
Unfortunately I encountered an error (even after I have deleted the second bracket after path2choosen_folder
that said:
"AppleScript-Fehler
"System Events" hat einen Fehler erhalten: alias "...<here comes the path2choosen_folder>..." kann nicht in Typ integer umgewandelt werden."
that means something like "... the alias could not be converted in type integer...".
Hmmm... why should an alias could be converted in a variable of type integer?!
Clueless,
Vlad Ghitulescu
Thanks for the quick reply!
Unfortunately I encountered an error (even after I have deleted the second bracket after path2choosen_folder

"AppleScript-Fehler
"System Events" hat einen Fehler erhalten: alias "...<here comes the path2choosen_folder>..." kann nicht in Typ integer umgewandelt werden."
that means something like "... the alias could not be converted in type integer...".
Hmmm... why should an alias could be converted in a variable of type integer?!
Clueless,
Vlad Ghitulescu
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Sorry, I've just figured that you live in Bochum (something about 20 km from my home - in Essen!
so that you probably don't need a translation 


Re: AppleScript Problem Under Snow Leopard
Hi Vlad,
hello neighbor!
Try to select a folder and open it in the finder then in "Darstellung" choose "DarstellungsOptionen" check "Alle Größen berechnen" and then click on "Als Standard verwenden"
That is what I did but was not shure if it was what made the difference. First I also had the missing value problem. Then I switched to size of disk item and it worked. you could also try
Tell me if this works.
Kind regards
Bernd
hello neighbor!

Try to select a folder and open it in the finder then in "Darstellung" choose "DarstellungsOptionen" check "Alle Größen berechnen" and then click on "Als Standard verwenden"
That is what I did but was not shure if it was what made the difference. First I also had the missing value problem. Then I switched to size of disk item and it worked. you could also try
Code: Select all
set x to (physical size of disk item (path2choosen_folder as text))
Kind regards
Bernd
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Hello again, Bernd!
Sorry, I have to correct myself:
1.- Your script works as expected:
set path2choosen_folder to "MacVlad HD:Users:Vlad:Documents:interesant:Vlad lernt AppleScript:Test:director"
tell application "System Events"
set current_size_choosen_folder to (physical size of disk item path2choosen_folder)
end tell
2.- This part of mine doesn't:
set path2choosen_folder to choose folder with prompt "Choose a folder:" default location alias "MacVlad HD:Users:Vlad:Documents:interesant:Vlad lernt AppleScript:Test:director"
tell application "System Events"
set current_size_choosen_folder to (physical size of disk item path2choosen_folder)
end tell
It get's the error message I have posted before.
This is my first AppleScript ever (!) so I really don't have any idea... do you?
Thanks again for the patience!
Best regards,
Vlad Ghitulescu
Sorry, I have to correct myself:
1.- Your script works as expected:
set path2choosen_folder to "MacVlad HD:Users:Vlad:Documents:interesant:Vlad lernt AppleScript:Test:director"
tell application "System Events"
set current_size_choosen_folder to (physical size of disk item path2choosen_folder)
end tell
2.- This part of mine doesn't:
set path2choosen_folder to choose folder with prompt "Choose a folder:" default location alias "MacVlad HD:Users:Vlad:Documents:interesant:Vlad lernt AppleScript:Test:director"
tell application "System Events"
set current_size_choosen_folder to (physical size of disk item path2choosen_folder)
end tell
It get's the error message I have posted before.
This is my first AppleScript ever (!) so I really don't have any idea... do you?
Thanks again for the patience!
Best regards,
Vlad Ghitulescu
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Hello at last 
The missing part "... as text" was essential - everything is fine now!
)
Thanks again & until next time (for sure!
)
Best regards,
Vlad Ghitulescu

The missing part "... as text" was essential - everything is fine now!

Thanks again & until next time (for sure!

Best regards,
Vlad Ghitulescu
Re: AppleScript Problem Under Snow Leopard
Hi Vlad,
try this:
it works for me
If you are learning AppleScript have a look at http://macscripter.net/
Kind regards
Bernd
try this:
Code: Select all
set path2choosen_folder to choose folder with prompt "Choose a folder:" default location alias "MacVlad HD:Users:Vlad:Documents:interesant:Vlad lernt AppleScript:Test:"
tell application "System Events"
set current_size_choosen_folder to (physical size of disk item (path2choosen_folder as text))
end tell
If you are learning AppleScript have a look at http://macscripter.net/
Kind regards
Bernd
-
- Posts: 6
- Joined: Tue Jun 21, 2011 5:03 am
Re: AppleScript Problem Under Snow Leopard
Hello again, Bernd!
Yes, it works for me too - thanks again.
I will take a look at MacScripter too (thanks for the links) - because the next problem seems to show up sooner as expected (again!
)... but more on this one after making my homeworks (Google is my friend, as well as MacScripter now!
) and get some sleep :-/
Thanks again and until then!
Best regards,
Vlad Ghitulescu
Yes, it works for me too - thanks again.
I will take a look at MacScripter too (thanks for the links) - because the next problem seems to show up sooner as expected (again!


Thanks again and until then!
Best regards,
Vlad Ghitulescu
Re: AppleScript Problem Under Snow Leopard
Hi friends,
why is AppleScript so extraordinary clumsy compared to LiveCode?!
This is a rethorical question
Can you imagine that Apple really considered to use HyperTalk as the scripting language for the MacOS?
Although the language was ready, present and available, it did not make it unfortunatly.
What a pity
Best
Klaus
why is AppleScript so extraordinary clumsy compared to LiveCode?!
This is a rethorical question

Can you imagine that Apple really considered to use HyperTalk as the scripting language for the MacOS?
Although the language was ready, present and available, it did not make it unfortunatly.
What a pity

Best
Klaus