Questions about 'use AppleScript version...'

(Phil Stokes) #1

Why do we have to put this line in scripts with ‘use’ statements:

use AppleScript version “…”

What happens if we leave it out?

Does it matter if we know the user is running on 10.11 or later?

I recently ran a script on Sierra with that line and (I think) version 2.4, which produced an error along the lines of ‘coudn’t find’ that version. It worries me that any scripts with the ‘use version’ line may end up causing problems in the future.

0 Likes

(Shane Stanley) #2

This is actually the subject of a blog entry Mark will be posting at some stage soon, on why it’s there in Script Debugger 6. But the short answer…

The main role is so that the user will get an error if they try to run it a script on an unsupported version. So it’s a good way to document the version requirements of a script for both author and runner. If you’re not concerned about that, or you want your script to support very old versions, there’s no need for it – but especially with things like script libraries and ASObjC, presumptions of backwards compatibility are more tenuous.

It also means you have a use statement when you start writing a script, so you probably need a use scripting additions statement if you’re intending to use scripting addition commands. If you don’t have either, and you decide to start using a script library later on, you have to remember to also add the use scripting additions statement, which in turn introduces some subtle changes (for the better) in behavior. And we think it’s generally better to start off with the new behavior to begin with, rather than risk surprises.

So on that basis, we think it’s modern AppleScript best practice, if you will.

And if you’re using ASObjC, Script Debugger’s code-completion uses the version information to exclude classes and methods that have been introduced since the version specified, so you don’t accidentally write scripts that won’t run where you need them to. If AppleScript introduces new commands, we will be able to do similar there.

You should never get an error if the version specified is earlier than that of the OS you’re running in; if you see that in Sierra, do log a bug with Apple.

3 Likes

(Phil Stokes) #3

Are the differences documented anywhere? I know the AS Release notes describe the changes, but they don’t actually tell you which specific API calls are now available that weren’t before.

0 Likes

(Shane Stanley) #4

At this stage the filtering applies only to Cocoa classes and methods used in ASObjC.

0 Likes

(Sean Murphy) #5

Does this ‘use AppleScript version’ line specifically use that version (Script Debugger’s default is 2.4 when creating a new application) or that as a minimum version? I just noticed that AppleScript is up to version 2.7 (since 2014). Is there a way to have Script Debugger create new apps with 2.7 instead? Is there a benefit to 2.7? We develop apps solely for internal use so there is no concern on supporting much older operating systems. High Sierra is the oldest we support in-house.

0 Likes

(Shane Stanley) #6

It’s a minimum version. To use 2.7 in new documents, just create your own template (File --> Save as Template…). You can then set the new template as your default in Preferences --> General.

0 Likes

(Sean Murphy) #7

Great. Thank you for the info @ShaneStanley

0 Likes