Balthisar Tidy’s support for AppleScript empowers you to put the power of automation to work for you. Here are just a few ideas of the things you can do:

  • Use a batch script to Tidy in place dozens, hundreds, or even thousands of files.
  • Supercharge the batch script to Tidy your files and copy them to a server directory.
  • Use Mac OS X’ Folder Actions to Tidy a file every time you save or copy it into the folders of your choice.

To get started making your own scripts, simply look at Balthisar Tidy’s AppleScript dictionary in the AppleScript editor of your choice.

Sample AppleScripts

Balthisar Tidy comes with several example scripts that demonstrate a little bit of the power the AppleScript offers to you. The scripts include added features that make Balthisar Tidy work even better for you, such as:

  • Use Balthisar Tidy as a batch processor for multiple document tidying.
  • Use macOS’ Folder Actions to automatically Tidy documents placed into a specific folder.
  • Scripts that can be installed into BBEdit or TextWrangler text editors in order to provide always-available, instant tidying from within those environments.

These sample scripts can be downloaded here.

Download from website.

Balthisar Tidy and Balthisar Tidy Service Helper

Some of Balthisar Tidy’s AppleScript functionality is provided by a separate, faceless, background application called Balthisar Tidy Service Helper. It’s a good option for using AppleScript instead of using Balthisar Tidy directly because it’s small, lightweight, and can produce Tidy’d text without loading the entire Balthisar Tidy application.

The APIs for both applications are described below.

The Balthisar Tidy AppleScript API

The Standard Suite

Balthisar Tidy supports the entire Standard Suite. Please consult Apple’s AppleScript documentation (see the sidebar for links) for a description of all of these features.

The Document Suite

While the Standard Suite gives you a lot of power, the Document Suite provides two additional AppleScript properties that will be critical to your automation workflow.

If you set this document property with some untidy HTML, it will be Tidy’d using the Preferences from Tidy options and made available immediately via the tidyText property.
This read only property returns the Tidy’d value of the sourceText that you set.

Developer Scripting Suite

The developer suite is primarily useful to the developers of Balthisar Tidy, but can offer some utility to you if also used with UI Scripting. In addition, because of application sandboxing, there is one critical property available in the developer suite that will be useful if you want to perform the equivalent of Save As… using AppleScript.

This read-only property displays the number of Preferences panels that are available in Balthisar Tidy’s Preferences window. Some variations of Balthisar Tidy have a different number of panels.
This property serves absolutely no purpose to normal developers whatsoever, unless you happen to have the need to hide the document window when the various helpers are shown. This may be the case if you want to take easy, clear screenshots of Balthisar Tidy’s various interface elements so that you can provide excellent, high-quality, world-class documentation.

When this property is true the document window will adjust itself to 100% transparency when helpers appear. This gives various screen shot utilities the ability to capture them without the document window in the background.

This read-only property returns the unique, internal identifier of the currently-visible preferences panel.
This property indicates/sets the currently visible preference panel. It uses a 1-based index.
This property indicates/sets whether the Preferences window is open or not (but not necessarily “visible” if occluded by another item on screen.)
Returns the POSIX path of the user-chosen directory after presenting a file open dialog to the user. Because Balthisar Tidy is sandboxed, the operating system prevents it from saving files to paths not specifically chosen by the user. Therefore instead of using AppleScript to ask the user to select a destination, ask Balthisar Tidy to ask the user instead. This path will remain valid until the next time Balthisar Tidy launches.
This read-only property returns the localized name of the currently-visible Preferences window panel.

AppleScript UI Scripting

In addition to its built-in AppleScript support, Balthisar Tidy also plays nicely with UI Scripting. See the link in the sidebar for more information about using UI Scripting.

The Balthisar Tidy Service Helper API

The Balthisar Tidy Service Helper API does not support the standard AppleScript suite. Rather it is a single purpose, lightweight tool to provide Tidying services without cluttering your screen with a GUI. It consists of a limited Application Suite toward this end.

The Application Suite

Unlike scripting Balthisar Tidy wherein all Tidying is document-based and contained within isolated containers, Balthisar Tidy Service Helper is a single instance. This means that the following properties are available system-wide to any AppleScript that chooses to use them.

If you attempt to use these properties simultaneously from multiple scripts running at the same time, your results could be quite interesting. It’s “safe” to do so in that no harm will come to your computer, but the results are subject to a first-come, first-serve basis that you have no control over. Still, they provide very light weight, very quick Tidying system wide.

If you set this property with some untidy HTML, it will be Tidy’d using the Tidy options in Preferences and made available immediately via the tidyText and tidyBodyText properties.
This read only property returns the Tidy’d value of the sourceText that you set. It will always return a full HTML document regardless of Balthisar Tidy’s show-body-only setting.
This read only property returns the Tidy’d value of the sourceText that you set. It will only ever return the body portion of an HTML document regardless of Balthisar Tidy’s show-body-only setting. This can be quite useful if you only wish to Tidy snippets of text.