AppleScript Problem Under Snow Leopard

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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 » Wed Jun 22, 2011 1:22 pm

Hi Klaus,
why is AppleScript so extraordinary clumsy compared to LiveCode?!
Don't get me started. The expletives would not be appropriate for a well behaved Forum like this one...

I think they neither really grasped what the power of Hyercard was and Applescript, well I think finally they understood that they have to support it: too many work-flows depend on it. But as to Applescript as a language they really should have ask the Hypercard team next door.

One thing I like in Applescript which is very powerful is that you can set the itemDelimiter to an arbitrary string longer one character or longer. This makes slicing text extremely flexible. Would be nice to have in Livecode.

Enough of that, in short: I wholeheartedly agree with you

Kind regards

Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: AppleScript Problem Under Snow Leopard

Post by FourthWorld » Wed Jun 22, 2011 3:45 pm

I share your sentiments on AppleScript, but fortunately many operations done with it can also be done with fewer layers using shell commands. Whenever you can find a shell equivalent you should be able to call it with the shell function in LiveCode and enjoy both simpler syntax and faster execution.

For file sizes in folders and volumes you can use "du" ("Disk Usage"). See "man du" in Terminal for details, or better yet check out this page which has additional notes:
http://ss64.com/osx/du.html

You can call this from within LiveCode with:

Code: Select all

put shell("du -sk <path>") into tVar
The "s" flag tells du to list only the specified file or folder, and the "k" flag tells it to use a recursive total for the folder's contents. "<path>" is of course where your path would go, e.g.:

Code: Select all

put shell("du -sk /Users/rg/Downloads") into tVar
The resulting value will be a return-delimited list in which each line gives the size of each path supplied to it and the path itself, e.g.:

556116 /Users/rg/Downloads

Getting word 1 of the value returned from your shell call will give you the total kb for the path supplied.

Since the path may contain space characters, it's probably a good idea to put the path in quotes:

Code: Select all

answer folder "Select a folder:"
put it into tDir
put shell("du -sk "&quote&tDir&quote) into tVar
put word 1 of tVar into tSize
Note that the value returned is the physical size, not the logical size, so it may appear slightly smaller than the value you see in the Finder's Get Info window. Physical size totals only the bytes actually used in the files, but logical size is the sum of the allocated space; on most OS X systems the smallest allocation block is 4k, so a file that has only 1k of data will be shown as a 4k file in Get Info, but as a 1k file with du.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply