Safety Emporium - Lab and Safety Supplies

AppleScripting QuickBooks 2009 Mac

Script Examples and Techniques: Page 6

On the previous page we saw how to use AppleScript to export QuickBooks data to Mail (or other programs) as well as how to print statements and reports. On this page, we will use AppleScript and JavaScript to do simple payroll for free. And don't worry, you don't need to know how to do JavaScript for this to work.

How Payroll "Works" in QuickBooks 2009 Mac

The Payroll "feature" of QuickBooks for Mac is not actually part of QuickBooks. It requires an external monthly subscription. While payroll can be complex, most small businesses have only a handful of employees and simple needs, in which case payroll services are extreme overkill and can cost hundreds of dollars per year.

To write your own payroll checks in QuickBooks, you simply set up several accounts and allocate funds to them as line items when you write the check. This is discussed in detail at Intuit and in one of our posts to the QuickBooks forums. While it appears daunting at first, it is really quite easy, and the scripts below will do it all for you once you've set up the accounts!

In this example, we have lumped the Medicare, Social Security, unemployment taxes etc. into the accounts shown. You could make sub-accounts in each of these for each employee to avoid having to tease individual data back out of them in Excel at the end of the year to generate W-2's. We've demonstrated that here under Salary only:

We will also assume that you have the employees listed as "Cunningham, Marion", "Jones, Jimbo", "Malph, Ralph" for check-writing purposes

You might have other Payroll expenses to add, or you might have multiple state payroll taxes (which we have in NJ, but we just lump them as one as we don't care to see the subdivisions). This is just a non-exhaustive example that you can use to learn how to add those yourself.

Calculating Payroll Amounts/Deductions

The big sell of payroll services is that they automatically update when the tax rates and thresholds change. That's a definite advantage, but those change once a year or less in most cases. If you actually read the mailings that your state and the Feds send you, you'll know when the changes are coming.

Another benefit of payroll services is dealing with taxes in which only the first $x of the employee's salary are taxable. So we've created a handy Javascript payroll calculator that does those calculations for you. And, in a moment, we will show you how to automatically import that data into QuickBooks 2009 for Mac to generate a payroll check!

First, a few comments about the calculator. You can use it on-line, of course, but we want you to save a copy of it to your hard drive so you can use a text editor to change the default settings to reflect the thresholds/rates in your state. Once you've done that, you can open the copy on your hard drive in your web browser when it's time to do payroll. Each calculation only requires four pieces of data, and you can hard code in three of them, so it will take you maybe 15 seconds to enter everything you need for the simple case we've set up.

We could have written the entire calculator in AppleScript, but AppleScript has limited abilities for user input. A web page form solves that issue. And then we used JavaScript within that web page rather than rely on AppleScript to do the calculations. This tutorial is about AppleScripting, not JavaScripting, so we won't dwell on the technical reasons for that decision.

Finally, note that we have only run and tested the calculator and AppleScript with the Safari web browser. If you want to figure out how to script other browsers, fine, but please don't ask us to do it.

Importing Payroll Calculations Into QuickBooks 2009 Mac

Once you have run the Javascript payroll calculator to figure out an employee's paycheck, you can run this script to bring the data right into QuickBooks! Simply leave the window with the calculated results open in Safari and then run this script which makes use of AppleScript's ability to read and send JavaScript events to web pages:

We haven't scripted hitting the OK button on the check input screen. With 14 lines entered in the check, we figured that you'd want to manually review things at least until you're sure that this script works reliably for you.

If the check is to your liking, click OK, and you're done with payroll entry for that employee. To enter more payroll checks, go back to your JavaScript Payroll Form, change the employee name (and amounts if necessary) and run this AppleScript again. It's that easy.

Using AppleScript to Fill out Web Page Forms

If you read carefully, you should have noticed that one can use JavaScript to not only get data from a web page form, but to enter or change the data as well. In other words, you can use AppleScript to automate all sorts of tasks, such as creating a shipment on the UPS web site or logging into a supplier's system to order new inventory! Even without forms, you can grab the entire contents of a web page and then parse out data you want such as stock prices, box scores, and more.

All of that goes beyond the scope of this tutorial, but to show you that it can be done, open our Javascript payroll calculator in Safari and then copy and paste this script into Apple's Script Editor. Check out how the indicated items change as you go along!

That's all the examples we have for now. We may add others as time permits, but can't guarantee that.

Table of Contents


Safety Emporium - Lab and Safety Supplies

Copyright 2008-2024 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.