SD8: Scripting Tabbed Windows

Script Debugger 8 is using system-provided tabbing for script windows, and as part of that change scripting support has been enhanced to include access to script window tabs. It has also resulted in a couple of less obvious changes.

To understand the way it works, it helps to have some understanding of how Apple implements tabs. Normal windows are easy to understand: window 1 is the frontmost window, and if you click on another window, it comes to the font to become the new window 1. Window indexes represent where windows appear in front-to-back layering order.

In a tabbed window, each tab actually represents a separate window, layered from the left tab to the right, with only the active tab’s window visible. When you click on a different tab to make it active, the order of the windows doesn’t change – all that changes is which one is visible.

Windows are represented in the AppleScript dictionary as ‘script windows’, and each ‘script window’ contains one or more ‘script window tabs’. The ‘script window tab’ class is a subclass of ‘script window’: the active ‘script window tab’ is also a kind of ‘script window’.

So if you ask for script window tab 1 of script window 1, the result will always be the left-most tab of the front script window, regardless of which tab is active. If a window has no tabs, script window tab 1 of script window 1 will be the same thing as script window 1.

To move a script window forwards or backwards, you can change its index property. To move a script window tab within the tabbed group — say, to move it from left-most to right-most — you change the script window tab’s tab index property.

Script windows and script window tabs have some new properties. As mentioned above, only one tab in each tabbed window is drawn at any time. But as far as the system is concerned, they are still visible until they are closed, which means the visible property is not very helpful. So script windows and script window tabs now have a content visible property, which returns true only if they are the active tab. Similarly, the current document property returns the document of the active tab.

One of the subtle changes in tab behaviour compared with previous versions of Script Debugger involves window bounds. Suppose you have two windows, and you tab one into the other, and you then resize the resulting window. When you get the bounds of the hidden script window tab, it will still be its original size. In previous versions, you would also see it at this size if you then dragged the tab back out into a window of its own.

However Apple’s tabbing works a bit differently. Although the hidden window will still return its original bounds, as soon as it gets drawn – which is required when it’s dragged or otherwise made active – it is immediately resized to the size of the visible tab.

To deal with this, script windows and script window tabs have a parent bounds property, which returns the bounds of the script window they belong to. And because of the way tabs work, you can probably think of it as the actual bounds, because that’s what it will be if such a tab ever gets made visible.

Script windows also have a tabbed property, which will tall you if it is a tabbed window.

Whether new windows are tabbed is controlled by the prefer tabs property, which has three options: yes, no and default. These match the settings in Script Debugger’s preferences, with default meaning to use the system-wide preference from System Preferences. The prefer tabs property replaces the open in tabs property, which has been renamed open tabs deprecated. You can still use the old property, but because it is a boolean value, it cannot map to all three choices.

Similarly, the open and make commands have a new prefer tab property, with the same three choices.