Balthisar Tidy for Work’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 for Work’s AppleScript dictionary in the AppleScript editor of your choice.

Sample AppleScripts

Balthisar Tidy for Work 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 for Work work even better for you, such as:

  • Use Balthisar Tidy for Work as a batch processor for multiple document tidying.
  • Use Mac OS X’s 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 are included on a disk image inside Balthisar Tidy for Work’s application bundle for your convenience, or you can download it here.

Download from website.

Balthisar Tidy for Work and Balthisar Tidy Service Helper

Some of Balthisar Tidy for Work’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 for Work directly because it’s small, lightweight, and can produce Tidy’d text without loading the entire Balthisar Tidy for Work application.

The APIs for both applications are described below.

The Balthisar Tidy for Work AppleScript API

The Standard Suite

Balthisar Tidy for Work 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 for Work, 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 for Work’s [Preferences][prefs_index] 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 for Work’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 for Work 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 for Work to ask the user instead. This path will remain valid until the next time Balthisar Tidy for Work 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 for Work 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 for Work 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 for Work’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 for Work’s show-body-only setting. This can be quite useful if you only wish to Tidy snippets of text.