Can someone show me the correct syntax for creating new records in X4 via applescript? I have a big workflow prepared which contains variables for the document title, URL, POSIX path to a PDF for attachment, etc. but I can’t figure out how to get EndNote to create a new record, let alone how to pass these parameters to it…
The create record command takes an XML string and creates a record from it. I would recommend create one reference that has some data in the fields you plan to populate. Then highlight that reference and go to “File > Export” and save the file as an XML file. Then open the file in a text editor to note the names of the XML nodes used for the data you want in the records. Here is one example that creates a new record. Note that the record list in EndNote will not display this reference until you click on a group and then back to the list.
tell application “EndNote X4”
set record_title to “Title of new record”
set record_author to “Last, First”
set record_year to “2011”
set record_url to “http://www.endnote.com”
set record_pdf to “file://localhost/Applications/EndNote X4/EndNoteX4MacHelp.pdf”
set xml to “<records><record><ref-type name=“Journal Article”>17</ref-type><contributors><authors><author>” & record_author & “</author></authors></contributors><titles><title>” & record_title & “</title></titles><dates><year>” & record_year & “</year></dates><urls><related-urls><url>” & record_url & “</url></related-urls><pdf-urls><url>” & record_pdf & “</url></pdf-urls></urls></record></records>”
If you want to create all of the records at once, you could use Import instead. The RSXML that Import takes allows for multiple records to be present in the XML unlike create record.
You can find the XML DTD in /Applications/EndNote X4/XML Support
Thanks so much for this. One other question: is there a way to force EndNote to make a copy of the PDF in its own data folder, as it would do if i dragged a PDF to the new record window?
Not using AppleScript, but you can have EndNote convert the PDFs afterwards. After the records are created you can select those, or all references, and go to “References > File Attachments > Convert to Relative Links.” This will have EndNote copy the PDFs you linked to directly, i.e. the ones you created via AppleScript, into the PDF folder just as if you attached the PDF by dragging it to the record.
Thanks for your reply. I’m still having some difficulty… Is there any documentation for the implementation of AppleScript in X4??
For example, in order to automate the “convert relative links” through UI Scripting, I need endnote to select the right record. Looking through the dictionary, it seems that “show records in” accepts a list of records which, conveniently, is what the “find” statement returns.
That said, this script fails (shown in an attachment – the forum won’t let me post code??). Nothing at all happens in my open EndNote document.
You may be able to use AppleScipt to execute “Edit > Select All” (Command+A) to highlight the list of references you have displayed.
But if you want all attachments in the library to be relative links you can select all of the references in the library and convert them to relative links once manually.