// Exporting data from MYOB with AppleScript

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:

  1. (*This script exports stuff from MYOB.*)
  2.  
  3. (*Set your paths, user and password here.*)
  4. set user_name to "Administrator" as string
  5. set user_pass to "admin-password" as string
  6. set path_export to "harddrivename:users:myname:Scripts:MYOB:Data:Export:" as string
  7. set path_myob to "harddrivename:users:myname:Documents:Accounts:MyBusiness-2009.myo" as string
  8. set myob to application path_myob
  9.  
  10. (*Start MYOB if required.*)
  11. tell application "Finder" to set tProcesses to name of processes
  12.  
  13. if (tProcesses contains "AccountEdge") then
  14. set myob_was_running to true as boolean
  15. else
  16. set myob_was_running to false as boolean
  17. activate path_myob
  18. tell application "AccountEdge"
  19. open path_myob as alias username user_name password user_pass
  20. end tell
  21. delay 2
  22. end if
  23.  
  24. (*Export what you done need.*)
  25. tell application "AccountEdge"
  26. export accounts to path_export & "accounts.dat" as string username user_name password user_pass
  27. export items to path_export & "items.dat" as string username user_name password user_pass
  28. export sales of type professional to path_export & "sales-professional.dat" as string username user_name password user_pass
  29. export sales of type item to path_export & "sales-item.dat" as string username user_name password user_pass
  30. export cards of type customer to path_export & "cards-customer.dat" as string username user_name password user_pass
  31.  
  32. (* export timesheets to path_export & "timesheets.dat" as string username user_name password user_pass *)
  33. export activity slips to path_export & "activity-slips.dat" as string username user_name password user_pass
  34. export activities to path_export & "activities.dat" as string username user_name password user_pass
  35.  
  36.  
  37. end tell
  38.  
  39. delay 2
  40.  
  41. (*Close MYOB if you opened it.*)
  42. if (myob_was_running is false) then
  43. tell application "AccountEdge"
  44. quit
  45. end tell
  46. end if
  47. ?>

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:

  1. 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 :)

  1. 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.

Comments

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 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

Add comment

Categories