Import script for DevonAgent to DevonThink

I’m trying to solve an important issue and I really need someone to point me in the right direction.
When Agent finds a search result and then sends it to DT via the “add results to Devonthink” option in the search set, the DATE is changed to the current date for both MODIFIED and CREATED columns. In other words, there is no information transferred about the actual DATE of the article.

So, I have been trying to figure out how to get that DATE field into the PDF export. I am using a script (I have no idea how to script) to try to add the DATE to the TITLE field but it just tells me that it can’t change the Title. Can someone take a look at this script and tell me what I’m doing wrong. I REALLY NEED TO FIGURE THIS OUT. Having hundreds of undated articles for research doesn’t work.
tell application “DEVONagent”
if not (exists search window 1) then error “No search window is open.”
set theSearch to search window 1
if searching of theSearch then error “Search is not yet complete.”
set theResults to search results of theSearch
repeat with theResult in theResults
set item_name to title of theResult & space & date of theResult as text
end repeat
on error error_message number error_number
display alert “DEVONagent” message error_message as warning
end try
end tell

Did you have to a look at the script ~/Library/Application Support/DEVONagent/Action Scripts/File results in DEVONthink as suggested?

I did, that is where I copied the code I am using from.

What I don’t know:

  1. when does the EXECUTE SCRIPT command run in Agent? Before or after the ADD RESULTS TO DEVONTHINK operation? If after, then I guess the DATE information from Agent is already lost before the script runs.
  2. is there a way to alter the meta data of the PDF file being sent to DT before sending it? Or do I have to find a way to save the DATE into a different place (that’s why I was trying to add it to the TITLE) and then figure out a way in DT to grab it and update the CREATION DATE in DT.
  3. Should I just use the SCRIPT you reference instead of the ADD RESULTS checkbox?

I appreciate your patience, I fear that I am perhaps not explaining my quandary clearly.


The script is another option in Window > Search Sets > Actions, see Execute Script action. It’s not related to the option to add results to DEVONthink, it adds them on its own and can be customized (e.g. to retain the date).



Sorry to be a pain, but … I need to get this working.

I have used the SEND FILES TO DEVONTHINK script and it works very well.
I have tried modifying it slightly by adding these few lines from one of Jim’s scripts hoping it would work. Now the script doesn’t even seem to run. Is my syntax wrong?

repeat with this_result in theResults
				set this_URL to |URL| of this_result
				set this_title to |Title| of this_result
				set thisYear to year of date as string
				set thisMonth to month of date as integer
				set thisDay to day of date as string
				set titleDateString to (thisYear & thisMonth & thisDay & "_")
				set this_title to titleDateString & this_title

My challenge seems to be that the DATE info can’t be added to a text (unicode?) field which TITLE is so I was hoping these lines of code would be a workaround.

The other option is near the end of the built-in script:
create record with {name:this_title, type:html, source:this_HTML, URL:this_URL} in theGroup
I tried adding date: date to this but it didn’t work

Finally, i noticed a FINDER COMMENT field in DT with some info from Agent search set that I might be able to add the date to - but I don’t see any access to that in the DA dictionary.

Thanks Carl (and anyone else). Been in DT since early 2000’s and I do love it but only recently discovering the true value of Agent.

This is incorrect. You’re not specifying what object the date is an attribute of.

And what format are you adding to DEVONthink?

May I ask why the “need to get this working” ?

I was adding PDF to DT, but now instead of using the CHECK BOX for send to DT, I am using the script provided with DA which sends HTML only.

The only challenge is that the results all go to DT with today’s date instead of the creation date of the source article.

I’ve been at this for days, literally. Learning as I go. But all I really want is to say “Devonthink use the date of the result as creation or modification date”.

sorry, as for the “why the need” question, it’s because I am doing research for a book. An article that says “60% of Americans live below the poverty line” is not helpful if I don’t know if that was 2001 or 2020. I could go back to the original source for each doc and update the date manually but that doesn’t make much sense.

The date used by DEVONagent is either the date returned by the web server, date specified in the HTML metadata or the first date found in the page. This is not necessarily the date of the article depending on the website.