AppleScript Problem Under Snow Leopard

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

AppleScript Problem Under Snow Leopard

Post by johnmiller1950 » Fri Oct 02, 2009 2:10 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Oct 04, 2009 11:56 pm

John,
I would test the script in the script editior (I think it has a new name in Snow Leopard) and see what is going on. I don't use Snow L. yet so I can not test it.
regards
Bernd

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

AppleScript Problem Under Snow Leopard

Post by johnmiller1950 » Mon Oct 05, 2009 11:13 am

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

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

AppleScript Problem Under Snow Leopard

Post by johnmiller1950 » Mon Oct 05, 2009 11:27 am

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

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

AppleScript Problem Under Snow Leopard

Post by johnmiller1950 » Mon Oct 05, 2009 11:30 am

One More Time

You can use "(get capacity of folder x)/1000/1000/1000" instead of adding the physical size & the free space.

John

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 5:08 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: AppleScript Problem Under Snow Leopard

Post by bn » Tue Jun 21, 2011 8:40 am

Hi Vlad,

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
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

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 9:13 pm

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

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 9:34 pm

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 :-D

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: AppleScript Problem Under Snow Leopard

Post by bn » Tue Jun 21, 2011 9:47 pm

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

Code: Select all

set x to (physical size of disk item (path2choosen_folder as text))
Tell me if this works.

Kind regards

Bernd

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 9:53 pm

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

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 10:07 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: AppleScript Problem Under Snow Leopard

Post by bn » Tue Jun 21, 2011 10:28 pm

Hi Vlad,

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
it works for me

If you are learning AppleScript have a look at http://macscripter.net/



Kind regards

Bernd

Vlad Ghitulescu
Posts: 6
Joined: Tue Jun 21, 2011 5:03 am

Re: AppleScript Problem Under Snow Leopard

Post by Vlad Ghitulescu » Tue Jun 21, 2011 10:52 pm

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

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: AppleScript Problem Under Snow Leopard

Post by Klaus » Wed Jun 22, 2011 12:35 pm

Hi friends,

why is AppleScript so extraordinary clumsy compared to LiveCode?!
This is a rethorical question :D

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 :cry:


Best

Klaus

Post Reply