I'm attempting to automate the filing of e-receipts into a digital filing application called Paperless from Mariner Software.
Within the Paperless AppleScript Dictionary, the following is defined for a receipt (class/data type):
receipt n [inh. library item] : A receipt. elements contained by .
properties merchant (text) : The merchant's name. amount (text) : amount of the receipt (as a string); can include currency symbol tax (text) : tax or VAT of the receipt (as a string); can include currency symbol payment method (text) : method of payment category (text) : category of receipt notes (text) : notes for the receipt date (date) : date of the receipt custom 1 (text) : custom data 1 custom 2 (text) : custom data 2 custom 3 (text) : custom data 3 file (file) : file reference for the receipt
responds to add.
In my AppleScript, I try to create a new receipt with the following code:
set MerchantID to "Apple -- testing"
tell application "Paperless"
activate
add receipt with properties {merchant:MerchantID}
end tell
However, it fails with the following error:
error "Paperless got an error: Can’t make receipt into type library item." number -1700 from receipt to library item
What confuses me about the error is that I am attempting to make a receipt which is a class that is inherited from the more general type library item.
Can someone explain how to create a new item based on classes defined like this?
Best Answer
receipt
is an element belonging to some parent object. As with any instance of an AppleScript element that has already been created, it'll typically be referenced either byindex
, e.g.or by
name
, e.g.or by
id
, e.g.My feeling is that the
add
command will act on an instance of alibrary item
(includingreceipt
) that already exists. If so, thenwould most likely generate the error you're seeing, because
receipt
is a class name, whereadd
would be expecting an identifiable element, e.g.Going by typical nomenclature in the AppleScript world,
add
commands typically get invoked when one wishes to take a pre-existing object from one location and insert/add it to another. InPaperless
, this might be taking areceipt
from, say, a folder (or album) of receipts, and adding either a copy of or a reference to (most likely the latter) that receipt to a different folder/album.The most common way to create new instances of an element in the majority of AppleScriptable applications is by way of the
make
command (which is part of the standard suite that an application's scripting dictionary is recommended to contain):If
Paperless
includes themake
command, try using that. It would take a form similar to:You will need to consider which element owns the collection of
receipts
in which you're attempting to create a new one. Iflibrary item
is a top-level application object, i.e. owned byapplication
, then themake
command should not require theat
parameter (if it does, it can be a genericat end of receipts
). However, iflibrary item
is owned by, say, alibrary
class object, then themake
command either needs to occur withintell
block targeting thatlibrary
element (e.g.library 1
, orlibrary "MyLibrary"
); or it needs theat
parameter to describe where to create the newreceipt
, e.g.where, for illustrative purposes, I've pre-supposed that
library items
are contained bylibraries
are contained bydocuments
are contained by theapplication
.