Version & Build Numbers

Script applets and bundles, like any other applications and bundles, support version numbers and build numbers, and the ability to set them has been part of Script Debugger for a long time. Script Debugger 8 expands on that support.

Before looking at the changes, let’s look at what these values are, and how they work.

You can see the version of an applet or bundle by choosing Get Info in the Finder, making it simple for anyone to check.

The first point to be aware of is that the version is not actually a number — it, and the build number, are strings. As such, they can theoretically contain just about anything. In practice, though, they should follow certain established conventions.

For versions, the convention is that they consist of up to three dot-separated numbers. The first number is known as the major version number, the second as the minor version number, and the third as the patch version number. The patch number is often dropped if it would otherwise be 0, whereas a minor version number is usually always included. So when you create a script applet, it has a version of “1.0”.

Although the convention is to use just numbers, it is not unknown to also use other characters — a beta version might be called version “1.1.1b1”. But even is such cases, there’s generally a trailing digit or digits in each field.

Of course, there are exceptions. Some applications have version “numbers” that include things like release dates and other information. You can use what you’re comfortable with. But the new features in Script Debugger are built around the conventions.

The build number is not displayed so prominently. It appears in a standard About… box, in parentheses after the version number, but you can’t generally access the About… command in script applets unless they are saved as stay-open. You can always display it in a script yourself if it matters, for example in a dialog title. But often build numbers are of more interest to the script author, as a way of tracking when changes were made.

Build “numbers” often also contain non-digit characters, but generally they end with a number, which is often incremented even when the version number is not.

In previous versions of Script Debugger, the version and build number were set in the resources tab, and could therefore only be set for applets and script bundles. In Script Debugger 8 they are set in the File → Bundle & Export Settings dialog. This means they can also be set for compiled scripts and text files. In such cases they are saved as metadata only, so are not accessible via the Finder’s Get Info command — but they are used if you export or save as an applet or bundle from those files.

Script Debugger has also had an option to have the build number automatically increment every time you save (this assumes your build number is in a format that can be incremented, with a trailing numeric value). Script Debugger 8 adds a new option: to instead increment each time a script is exported. (Because changing the build number modifies a document, you need to save after exporting if you choose this option.) You select either option, or manual incrementing, in the Bundle & Export Settings dialog, where there is also a stepper control to manually increment/decrement the value.

The version number field has been split into three fields, for the major, minor, and patch numbers. There is no need to enter dots.

There is also a new Versions submenu in Script Debugger’s File menu. The first two items do nothing other than display the active document’s version and build number. The next four commands increment the build number, major version number, minor version number, and patch version number, respectively. They also show the updated versions in the status bar, if it is showing.

The increment commands rely on the version numbers following the conventions above, in terms of having trailing numbers to increment. When a minor version number is incremented, any patch number is discarded. When a major version number is incremented, the minor version number is set to 0 and any patch number is discarded.

Here are samples of versions and how they are increment by the commands:

Version Increment Major # Increment Minor # Increment Patch #
1 2.0 1.1 1.0.1
1.0 2.0 1.1 1.0.1
1.0.1 2.0 1.1 1.0.2
1.0.1b1 2.0 1.1 1.0.1b2
1A.0 1A1.0 1A.1 1A.0.1

Build numbers increment similarly:

Build # Incremented Build #
1 2
1.0 1.1
1.1 1.2
1A 1A1
1A1 1A2

One slightly confusing aspect of these numbers is that for applets and bundles they are stored in the bundle’s Info.plist file, and when Script Debugger opens an applet or script bundle, the operating system caches the contents of this file, and the contents in memory cannot be modified.

So let’s say you have a new applet open in Script Debugger and you run this code:

display dialog (my version)

It will show “1.0”. If you now increment the version number and save, when you run the script again, you will still get the cached result of “1.0”. But if you run the applet itself, or choose Get Info on the file in the Finder, you will see the updated version. To get the correct version using this code in Script Debugger, you will have to quit and relaunch after making the change. (The same applies to all the Info.plist entries.)

Getting the build number via script is more complicated, and requires the use of AppleScriptObjC:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theApp to path to me
set theBundle to current application's NSBundle's bundleWithURL:theApp
set buildNum to theBundle's objectForInfoDictionaryKey:"CFBundleVersion" -- yes, that's the correct key
if buildNum is not missing value then set buildNum to buildNum as text

Mark, I couldn’t get your script to run without a minor tweak.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theApp to path to me
set theApp to POSIX path of theApp
set thisURL to (current application's |NSURL|'s fileURLWithPath:(theApp))
set theBundle to current application's NSBundle's bundleWithURL:thisURL
set buildNum to theBundle's objectForInfoDictionaryKey:"CFBundleVersion" -- yes, that's the correct key
if buildNum is not missing value then set buildNum to buildNum as text

That said, I’m having an issue with incrementing the build number in a script.

I’m using the above script and saved it as a script bundle.

The first couple times I incremented the build number it worked fine.

But the third time I incremented the build number and, without saving, ran the script.

The build number for the bundle didn’t change. But in the menu it had changed. After that whether or not I saved the file the build number for the bundle wouldn’t change when I incremented it, but the menu display would change.

→ Script Debugger: 8.0.2 (8A39)
→ buildNumbersBundle: 1.0 (2)
→ Mac OS: 11.6 (20G165)

What I think has happened is that the menu has become out of sync with the actual build number. I closed the file and reopened and it’s still out of sync.

The menu says Build #: 4

But the script returns 2.

What happens is the system caches the version number when a script is opened. Then when you change the number in Script Debugger and save, the files is changed, but the system still uses its cached value.

Or maybe the opposite? The number is changed in the UI (cached version?) but not in the file. If I close the file and look at it from another source it’s not updated.

I can’t reproduce that. Can you make a video of that happening?

https://caltimes-my.sharepoint.com/:u:/g/personal/ed_stockly_latimes_com/EfCGNR5sLrNElwdnT1aCGLkBKT0qGDuwrEFkMbdUldCFrg?e=9x3cSv

Video and script

Dang. I zipped the script and movie together by Microsoft’s One Drive “helpfully” unzips them.

What’s up with that? DropBox and OneDrive have never heard of bundles?

Hey Ed,

Not really. It just displays the contents.

If you download the file you’ll only get one “BuildBundle.zip” file.

-Chris

If I close Script Debugger and open the script again, then everything is ok. Otherwise I have the same behavior. The version seems to be cached.

It’s as Dirk said: the version is cached by the system. If you look inside the bundle at its Info.plist file, you will see the version has been changed.

Sometimes you don’t need to quit and relaunch Script Debugger, but other times you don’t. Unfortunately we have no control over when the cache is cleared.

OK, but here’s what I think was confusing me. I get different results running the script above than I would see in either the SD interface or looking at the plist.

I would have expected the script to return the same as is in the plist, with SD displaying an older, cached version.

Either way I think this oddity has been resolved.

I don’t know why the values are cached, but if I had to guess, I’d say it’s because some Info.plist values relate to security settings, and having them modifiable after launch (opening an applet in an editor is seen as similar to a launch) would be a rather large security hole. As I say, pure speculation.