Help with script to generate citation from email or listserv message?

Hi,

I’m working with a database that includes many email and listserv messages which I need to quote and cite formally. I wanted to create a simple script to automatically pull specific metadata (sender name, message subject, creation date) into the clipboard in a specific citation format (in this case Chicago style, but I could tweak it for other styles).

I am an AppleScript novice and I thought I’d see what ChatGPT came up with and mess with it until it works, but the script just fails with no message. I can’t tell if the variable names are off, or if the whole structure is wrong. If anyone can point me in the right direction I’d appreciate it!

This is the script I’m starting with. Sorry for bringing CGPT into it!

tell application "DEVONthink 3"
    set selectedRecords to selection
    if selectedRecords is {} then
        display alert "Please select an item in DEVONthink first." message "No item is selected." as warning
    else
        set selectedItem to item 1 of selectedRecords
        set citationText to generateCitation(selectedItem)
        set the clipboard to citationText
        display notification "Citation copied to clipboard" with title "Success"
    end if
end tell

on generateCitation(selectedItem)
    -- Extract necessary information from the selected item and format it as a citation
    -- You'll need to customize this part based on the structure of your listserv messages
    -- For now, let's assume you have placeholders for sender, title, date, and listserv name
    set senderName to name of sender of selectedItem
    set messageTitle to name of selectedItem
    set messageDate to modification date of selectedItem
    set listservName to name of parent 1 of selectedItem
    
    -- Customize the citation format according to Chicago style
    set citationText to "Author: " & senderName & return & "Title: " & messageTitle & return & "Date: " & messageDate & return & "Listserv: " & listservName
    
    return citationText
end generateCitation

thanks
Lucas

I suggest starting with any of the gazillion scripts to be found here in the forum. ChatGPT is notorious for hallucinating AppleScript code.

Also, JavaScript could be used as a scripting language. Which is not to say that chatGPT is any better inventing JXA code.

Generally, it pays off to learn the tools of the trade.

1 Like

The problem is that ChatGPT doesn’t know the Dictionary of the DT.
You need to see record class in dictionary and decide which exact properties of the record you need.

For example, there is no such property as name of sender. If you don’t have previously created such a custom meta data (like with litservName), then the only place you can get the Author - is in metadata property of the record if any. It’ll be something like item 1 of kMDItemAuthors of metadata of selectedItem.

If the Title is the name of the record, then it is name of selectedItem

For Date, there are many options, like date, creation date, modification date, addition date.

So, you need to see the Dictionary of DT first.