Safety Emporium - Lab and Safety Supplies

AppleScripting QuickBooks 2009 Mac

Script Examples and Techniques: Page 2

On the previous page we looked at some full-length examples of scripts that interacted with Quickbooks.

Handy Routine #1 - Wait for QB to Be Ready

QuickBooks 2009 Mac can sometime be slow to open a window or load. As a result, if you send emulated keystrokes to QB in a script and QB it is still busy, the keystrokes will arrive before QB is ready and things can go a bit haywire. The following scriptlet can be used to check that QB is ready before you start sending it commands.

In the subroutine, the 1 to 60 loop is aribitrary, but you definitely want it to be several seconds longer than it takes for QB to launch on your system. The value of 30 *sent* to the subroutine is an empirically determined level of CPU cycles that we came up with based on watching what QB was doing while Apple's Activity Monitor window was open. You can adjust that level up or down depending on how QB behaves on your system.

Handy Routine #2 - Find/Replace

Oddly, AppleScript lacks a basic Find/Replace command. Which is a royal pain if you want to do something like replace "Street" with "St" in addresses. Luckily, Apple has published a general subroutine for Find/Replace:

We can test this subroutine out by typing the following lines above the subroutine in Script Editor and looking at the results in the Event Log window.

But an even easier way to handle Find/Replace is to utilize an OSAX as discussed on the first page of this tutorial. Satimage OSAX contains powerful find/replace commands as well a whole host of other very powerful features such as expanded mathematical functions, arrays, list utilities, and text manipulation capabilities. The speed boost when processing large text files with the OSAX installed can be 10x or more!

On the next page we'll see some really nice and powerful techniques.

Table of Contents

Safety Emporium - Lab and Safety Supplies

Copyright 2008-2023 by Interactive Learning Paradigms Incorporated. All rights reserved. Reposting of this material is not permitted and constitutes a violation of US and International copyright law.