import string

## This script changes all transactions with the given payee
## to have the specified account/category

rootAccount = moneydance.getRootAccount()

## Change the payee (case insensitive) in the next line
payee = string.upper("CITY OF RICHMOND")

## Change the account/category name below to the one that should
## be given to the transactions with the above payee
acct = rootAccount.getAccountByName("Utilities")

print "categorizing transactions with payee '%s' to account '%s'"%(payee, acct)

if payee and acct:
  txnEnum = rootAccount.getTransactionSet().getAllTransactions()
  while txnEnum.hasMoreElements():
    txn = txnEnum.nextElement()
    if txn.getParentTxn()==txn and string.upper(txn.getDescription())==payee:
      print "matched txn: %s"%(txn)
      for splitNum in range(0, txn.getSplitCount()):
        txn.getSplit(splitNum).setAccount(acct)

rootAccount.refreshAccountBalances()

