Applescript Suite

Use Applescript commands to interface MoneyWorks to other programs running on the same Mac.

Note: As of v7, the recommended technology for implementing automation within MoneyWorks is MWScript.

Unless otherwise noted, AppleEvents are only accepted if there is no modal dialog box open on the screen. As a general rule, if the quit command is currently available, these appleevents can be processed. If MoneyWorks is busy, you will get error number 500.

Required Suite

open: Open the specified object(s)

Usage:

open item -- list of objects to open (file, alias)

Example:

tell application "MoneyWorks Gold" to open file "Hard Disk:Applications:MoneyWorks Gold Folder:XYZ Accounts"

This will open the specified document, closing any currently open document. This command can also be used to open report files (but this is not very useful)

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 

print: Print the specified object(s)

Usage:

print item -- list of objects to print

Example:

tell application "MoneyWorks Gold" to print file "Hard Disk:Applications:MoneyWorks Gold Folder:MoneyWorks Standard Plug-Ins:Reports:Balance Sheet"

This will print the specified report (bringing up the settings dialog). An accounts document must already be open to provide a context for the report.

This is not the recommended way of generating reports—use do report

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 
506 no document is open 

quit: Quit application

Usage:

quit

Example:

tell application "MoneyWorks Gold" to quit

Asks MoneyWorks to quit.

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 
505 MoneyWorks refused the quit event (user may have aborted) 

MoneyWorks Suite

import: Imports data from a text file using a specified import map.

Usage:

import data using map map

data can be the actual textual data to import, or a reference to a text file.

map can be the name of an import map residing in the Import Maps subfolder of the Custom or Standard Plugins folder; or a reference to an import map file anywhere else; or it can be text containing an xml argument block, described below.

Example:

tell application "MoneyWorks Gold" to import file "Hard Disk:Documents:SomeData.txt" using map "Named Map"

You must already have set up and saved an import map to suit the data being imported. MoneyWorks determines where the records are to go from the import map (i.e. if its a Name import map, they will be names). If any errors are encountered with the data, the entire import is aborted, and your script will get an error number 503.

MoneyWorks Gold 4.0.6 and later:

The map parameter may be xml text containg a single "args" tag with the following attributes:

<?xml version="1.0"?>

<args file="transaction"

   map="updatemap"

   update="true"

   post="true"

   seqnum="999"/>

Yes, the <?xml version="1.0"?> is required.

file must be present. Useful values are "transaction", "account", "user", or "build". You can import into other files this way but there is no point—just use the regular syntax. If it's "account", the import data should be in the same format you get when you Copy accounts from the accounts list.

map must specify the name of an import map in the Plug-Ins if the file is "transaction".

update is optional for transactions. If true the import data must specify a single invoice to replace an existing transaction whose sequence number is specified using the seqnum attribute. If the invoice identified by seqnum is not posted, then it gets deleted upon successful import of the new transaction (new one effectively replaces it). If the invoice is posted (and providing any payments are not processed for GST), it is cancelled. If there were any payments on it, they become overpayments which may then be (manually) allocated to the new (or any other) invoice.

post is optional for transactions. Transactions are posted on successful completion of the import

Note that from Applescript, the quotes in the xml will need to be escaped with a \

If the file is "build", You are importing build recipe data for manufactured products. The import data must contain the fields: ProductCode, Qty, PartCode in that order, tab-delimited.

If the file is "user", you are importing any persistent data that you may need to store—usually in support of your external system—the import data must contain the fields: Key, Data, in that order, tab-delimited (key is up to 9 chars (must not start with '#')). Data can be up to 255 chars.

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 
501 the named import map could not be found 
502 the logical file name is not valid 
503 errors in import: non-specific 
506 no document is open 
509 Update Failed Due To Lock 
510 Privilege Violation 
511 errors in import: specific 

export: export data from specified file

Usage:

export filenamestring -- the name of the file to export from (e.g. "Job")

[using search string] -- a search expression (e.g. "Gross > 500")

[into file -- a reference to a text file to export into

Possible values for filenamestring are: "Account", "Ledger", "General", "Department", "Transaction", "Detail", "Log", "TaxRate", "Message", "Name", "Payments", "Product", "Job", "Build", "JobSheet", "BankRecs", "AutoSplit", "Memo", "User".

Example:

tell application "MoneyWorks Gold" to export "Transaction"using search "TransDate &gt; \"31/5/96\"" 

This returns the matching transaction records as tab-delimited text. You get every field from the record, including some gobbledgook ones that wont mean much to you.

tell application "MoneyWorks Gold" to export "Job" into alias "Hard Disk:Some Jobs"

This exports all job records (since there is no search specification) to a file called “Some Jobs” on the hard disk. (We use alias instead of file, since the file does not yet exist)

Special Searches

Using "=" as the search expression will export a single "record" containing just the field names for the file

Using "*" as the search expression will give you the highlighted records in the main list window belonging to the file you have asked for, or all records if there is no highlighted selection

Using "**" as the search expression will give you the highlighted records in the main list window belonging to the file you have asked for or none if there is no highlighted selection

The 4.1.4 export syntax allows the 'filename' parameter to contain formatting information that specifies what is to be exported:

export "Filename[.sortfield[-]][#formatstring]"

sortField can be included to sort the export by that field

sortField can have a "-" appended to specify descending sort

formatstring can specify what to export. Everything in the format string is returned verbatim except for anything inside [...] which is treated as an expression which can reference the fields of the file being exported. Thus if you want tab-delimited, then put tabs between the expressions. You can use metacharacters \t \r \n \xHH (hex) or \\. Note that since Applescript expands the same metacharacters, you are best to use meta-metacharacters in applescripts, e.g. \\t \\r \\x0a etc

As of v6.1.1, If the format string is exactly the text "xml", then the records will be exported as xml.

examples (Applescript)

export "Name"

same as usual

export "Name.Code-"

export in usual format but sorted descending by code

export "Name.Code-#[Code],[Phone]\\r"

export code and phone number separated by a comma with lines delimited by a Return character

export
"Name.Code-#\"[Code]\",\"[Phone]\"\\r\\n"

as above, but fields are quoted, and line delimiter is MSDOS-style

export
"Ledger.concat#\"[AccountCode + if(Department != ``, `-` +
Department, ``)]\",\"[Lookup(AccountCode, `Account.Description`)+
if(Department != ``, ` (` + Lookup(Department, `Department.Description`) + `)`,
``)]\",\"Y\",\"[Lookup(AccountCode,
`Account.TaxCode`)]\"\\r"

exports account codes in banklink format

Added ?path option for importing and exporting on Windows: If file path stars with ?, use it as default but put up a dialog box (the given filename extension in the path will be respected)

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 
502 The logical file name (i.e. "Job" in the above example) is not valid 
504 Bad search expression. MW could not do the search (try it out in the
    advanced Find dialog box [option-Find] to make sure it works) 
506 No document is open 

do report: run a named MoneyWorks report(s)

Usage:

do report reportname -- the name of the report

[from period string] -- a date (as text, e.g. "31/3/96") within the

tarting period to run the report for

[to period string] -- a date (as text, e.g. "31/3/96") within the ending period to run the report for

[outputting to printer/preview/text file] -- where to send the report (if no destination specified, text is returned as command result)

[spooling to file] -- the text file to export into (if output option is text file)

[job dialogs boolean] -- if false, no dialogs are shown (this is the default)

Examples:

do report "Profit Report" from period "1/4/96" to period "1/4/96"¬

   
outputting to text file spooling to file "Hard Disk:EIS folder:Profit rep.text"¬

   without job dialogs

This runs the reports for the (entire) period in which the date 1/4/96 falls. The result is exported to the text file and the settings dialogs are bypassed (the user does not need to do anything). Any settings you want (except the period range) must already have been set up in the report. If you need to do the same report with different settings, save copies of the report with those settings already set.

do report "Profit Report" without job dialogs

Runs the report for the current period, and returns the tab-delimited text of the report to AppleScript.

Note: If the output is not specified, the job dialogs must be suppressed.

do report "Profit Report" outputting to preview

Brings up the settings dialog for the report, with the output set to preview. The user can change the output option, settings etc, and can even cancel it if they want.

Important Note: The “job dialogs false" (or “without job dialogs) option currently only works for ordinary custom reports (not Analysis, hardwired, alias, or chain reports). Notice also that there is currently no way to supply settings to other types of reports (only a date range).

Possible errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up)
506 No document is open
507 Report name not recognised
508 User cancelled report (this can happen even if you suppress the dialogs) 

evaluate: Evaluate an expression using the built-in expression parser

Usage:

evaluate expressionText

Example:

evaluate "Today()"

returns today's date (as text)

evaluate "1 + 1"

returns "2"

evaluate "Lookup(`1000`, `Account.Descripton`)"

Returns the name of account 1000. Note that quotes in the expression have been done using backquotes ` instead of ". MoneyWorks treats ` as " for this purpose. In Applescript you can also pass an actual " by escaping it thus \".

Possible errors:

Any parser error—error message will be returned in Apple Event error message

Full list of possible AE errors:

500 MoneyWorks can not service AE requests at this time (modal dialog up) 
501 the named import map could not be found 
502 the logical file name is not valid 
503 errors in import: non-specific 
504 could not understand expr 
505 MoneyWorks refused a quit event 
506 no document is open 
507 report name not present 
508 the user cancelled report generation 
509 Update Failed Due To Lock 
510 Privilege Violation 
511 errors in import: specific 
	
Posted in AppleScript | Comments Off on Applescript Suite