Exporting data from MYOB with AppleScript

We wanted to display MYOB Account Edge data in our support site on the corresponding company page. Ideally you'd like to get the database, but there are no stable database driver options for Account Edge.

I found some examples on the US MYOB site which got me started with both the MYOB script library as well as AppleScript (crap, I'd prefer VBA over this, but it works).

Here is the script:

(*This script exports stuff from MYOB.*)
 
(*Set your paths, user and password here.*)
set user_name to "Administrator" as string
set user_pass to "admin-password" as string
set path_export to "harddrivename:users:myname:Scripts:MYOB:Data:Export:" as string
set path_myob to "harddrivename:users:myname:Documents:Accounts:MyBusiness-2009.myo" as string
set myob to application path_myob
 
(*Start MYOB if required.*)
tell application "Finder" to set tProcesses to name of processes
 
if (tProcesses contains "AccountEdge") then
	set myob_was_running to true as boolean
else
	set myob_was_running to false as boolean
	activate path_myob
	tell application "AccountEdge"
		open path_myob as alias username user_name password user_pass
	end tell
	delay 2
end if
 
(*Export what you done need.*)
tell application "AccountEdge"
	export accounts to path_export & "accounts.dat" as string username user_name password user_pass
	export items to path_export & "items.dat" as string username user_name password user_pass
	export sales of type professional to path_export & "sales-professional.dat" as string username user_name password user_pass
	export sales of type item to path_export & "sales-item.dat" as string username user_name password user_pass
	export cards of type customer to path_export & "cards-customer.dat" as string username user_name password user_pass
 
	(* export timesheets to path_export & "timesheets.dat" as string username user_name password user_pass *)
	export activity slips to path_export & "activity-slips.dat" as string username user_name password user_pass
	export activities to path_export & "activities.dat" as string username user_name password user_pass
 
 
end tell
 
delay 2
 
(*Close MYOB if you opened it.*)
if (myob_was_running is false) then
	tell application "AccountEdge"
		quit
	end tell
end if
?>

The script is not perfect, but most of the time it successfully determines if MYOB is open (opens it if not) and runs the export commands. I run this with a crontab entry every hour:

30 * * * * '/Users/myname/Scripts/MYOB/MYOB Data Export.app'

This produces a set of tab and carriage-return (/r in php) delimited files which are then pushed to the server with scp each hour a few minutes later. But you'll need to set up private keys for this to work without requiring a password - I get Tanc to do that for me :)

40 * * * * scp -r /Users/myname/Scripts/MYOB/Data/Export/* user@example.com:/home/user/myob_data

Check out how we imported this data into our database here.

If there is any interest in this article I'll later discuss importing and using the data in Drupal.

Hey thanks for this. Have

Hey thanks for this. Have used Accountedge for a while now but have often wondered how to export the data. Now I know!

For those who have the myo file on an NFS mount use the mount name you see in Finder for starting with in the path_export statement. eg: I had an automount set up that had a 'companyname' icon in Finder, so I just started with "companyname:MYOB.company.myo".

Also ... For bigger MYOB

Also ...

For bigger MYOB files you also might like to enclose the export "tell application" with a "with timeout" statement:

with timeout of 1200 seconds
tell application "AccountEdge"
export ...
.
end tell
end timeout