Help to modify script to add imported document to Reading List

Hi, I’ve been using the following script to monitor a folder to add reading material to Devonthink and add a task to Omnifocus. Now that Reading LIst syncs across devices, I would also like to add the imported document to the Reading List. Any suggestions would be welcome!

-- DEVONthink - Import, OCR & Delete.applescript
-- Created by Christian Grunenberg on Fri Jun 18 2010.
-- Copyright (c) 2010-2014. All rights reserved.
-- Add to OmniFocus portion of the script from David Sparks
-- Scripts mashed up to Import, OmniFocus, & Delete by Chris Upchurch

on adding folder items to this_folder after receiving added_items
	--say "Script Launched"
	try
		if (count of added_items) is greater than 0 then
			tell application id "DNtp" to launch
			--say "App launched"
			repeat with theItem in added_items
				set lastFileSize to 0
				set currentFileSize to 1
				repeat while lastFileSize ≠ currentFileSize
					delay 0.5
					set lastFileSize to currentFileSize
					set currentFileSize to size of (info for theItem)
				end repeat
				
				try
					set thePath to theItem as text
					--say thePath
					if thePath does not end with ".download:" then
						--say "Not download"
						tell application id "DNtp"
							--say "DNtp"
							--if exists incoming group then say "Incoming"
							set theRecord to import thePath to incoming group
							if exists theRecord then tell application "Finder" to delete theItem
							--if exists theRecord then say "Exists"
							set theTask to "Read/Review: " & name of theRecord
							set theURL to reference URL of theRecord
							--say name
							--say theURL
						end tell
						tell application "OmniFocus"
							tell default document
								set theTag to (the first flattened tag where its name = "Anywhere")
								set theProject to (first flattened project where its name = "Read/Review")
								tell theProject
									set newTask to make new task with properties {name:theTask, note:theURL, primary tag:theTag}
								end tell
								
							end tell
						end tell
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

I think you should rethink this line…

if exists theRecord then tell application "Finder" to delete theItem

If the record doesn’t exist, the Finder does nothing, but DEVONthink continues on with following statements. This behavior is likely masked by the try… end try block. I suggest you don’t add try blocks while you’re developing a script. Let it error in your face so you know things aren’t working correctly.

While this isn’t a rewritten version of your script, I would handle the DEVONthink part of it with…

if exists theRecord then
    set theTask to "Read/Review: " & name of theRecord
    set theURL to reference URL of theRecord
    add reading list record theRecord
    tell application "Finder" to delete theItem
end if
end tell

And here’s a basic example…

set r to "~/desktop/hang-on-bookmark.txt"

tell application id "DNtp"
	set newRecord to import r to current group	
	if exists newRecord then
		add reading list record newRecord
	end if
end tell

Thanks, Bluefrog. That seems to have done the trick!

You’re welcome!
:slight_smile: