AppleScript Stopped Working

Hi All,

Back when XOJO was RealBasic / RealStudio I created an app that returned values and counts of folders by AppleScript.

The files where added to the project and then called :

On Open:

Logs_Cache_Size.caption = Logs

Apple Script: (Logs)

on run
	set Cache_size3 to (do shell script "du -h $HOME/Library/Logs/ | tail -rn1 | awk '{print  $1}'")
end run

This would return for example 44M

When I try to do this in the latest version of XOJO I get a blank returned. To test that the AppleScript worked, I’ve run it in isolation; works, and also added AAA to the caption text, which I see on load get changed to a blank.

Any ideas?

Ive also tried:

on run set Cache_size3 to (do shell script "du -h $HOME/Library/Logs/ | tail -rn1 | awk '{print $1}'") return Cache_size3 as text end run

IMHO AppleScript is unofficially deprecated.

It looks like you’re basically trying to get the file size of the logs folder, if true, you can do that with pure native Xojo code.

Simply get a folder item that points to that folder and loop through all the files (and any sub folders), appending folderitem.length to a UInt64.

Hi @Sam Rowlands ,

Here is the funny thing. If I call the Script of a Button.Action : Label1.Text = Logs. then it Works!

With regards to the deprication statement, is there a noob’s guide on how to do what you have suggested?

Ohh !? :frowning: .
I hope you’re wrong, I have a lot of AppleScript I made for my own use.

To Fix this I just added a timer for 200 of a second, as it seems to be a race condition! I will look into the Folder Option

If you like to get directory size quickly, please try DirectorySizeMBS class in MBS Xojo Plugins.

What about:

AppleScript is slow (very slow) when dealing with files.

Since the REALbasic days, I slowly but surely stopped to use AppleScript. In the last days, I only used it to test ideas that I implemented in Xojo.

My real last use of AppleScript was to build html files to download images; this was so slow that I trashed that script and create a Xojo project that do the job in second(s), 1 or two, when the script takes its time (time to drink a cup of coffee); go figure.

Only AppleScript advantage ? Fast typing, running, implementing back in Xojo.
Last tip from AppleScript ? How to detect an image property: what is the image orientation (tall > wide or the reverse…). Some seconds to write / some seconds to implement in Xojo, and I understand I can stop using AppleScript.
Now I use AppleSript to quit the Finder when I am very short in memory :wink:

A tool is just what it is: a tool. When you find one that better meet your needs, forget the previous ones if possible; else, you will waste your precious time, even your home time is valuable.

It works
Why not, but one may ask himself if there is not a better (and not implementation time consumming) solution.

One can even refactor the previous version to get a far better application (even for home/ in house use).


I like AppleScript a lot, but since OSX I tend to use the shell as much as I can (not only it usually is faster, but it also uses less resources for the most part and it may be easier to reuse in other platforms).

I adore AppleScript for what it is and what it’s meant (it’s still some of the easiest programming out there, although with the loss of Hypercard it lost an enormous amount of steam, and its Xcode implementation never covered that specific use case in most users).

Nowadays, I use AppleScript only for short scripts that access system-specific functionality harder to do otherwise (and this means, in most cases, that AppleScript is really the “poor man’s declare”, since things like quitting the finder, revealing a file or using speech to text could be as easily be done with declares but I’m too lazy to try :slight_smile:

Having said this, I hope AppleScript doesn’t disappear but remains as one more tool in the toolchest of what’s today the most automatable and scriptable operating system in the world (MacOS has all the scriptability of unix and linux plus all the scriptability of AppleScript and JavaScript plus Swift) and also Automator to tie everything up if you wish to make simple workflows. And of course the ability to run every one from all the rest (running applescript from a shellscript and shellscripts from applescript opened so many doors for me…)