How to import CSV of URLS as Web Archives (with Tags)?

Hello humans.

I’m trying to move my Pocket content into DEVONthink Pro.

I imported a CSV to a DEVONthink sheet with the following columns:

  • URL
  • Title
  • Tags (multiple in one cell separated by commas)

The basic process would need a script that starts at the second row, creates a web archive from the URL, applies TITLE, adds TAGS, saves record to a group, repeat… My assumption is that importing various sorts of content via CSV with a method like this is a very common use case – most apps that allow users to export their content provide it as a CSV or JSON dump. However, despite trying a dozen searches with various phrases/terms, I haven’t come across any conversations here that address this. Am I missing something?

I have unsuccessfully played with this a bit using other community posts as inspiration, such as this one and this one.

Can anyone point me the right direction?

Thanks in advance :slight_smile:.

My assumption is that importing various sorts of content via CSV with a method like this is a very common use case

That’s almost always a dangerous thing to do. :stuck_out_tongue:


This is a simple example using a two column sheet…

tell application id "DNtp"
	repeat with thisRecord in (selection as list)
		if (type of thisRecord) = sheet then
			set sheetData to (cells of content record of think window 1)
			repeat with thisData in sheetData
				try
					set newRecord to create web document from (item 1 of thisData) in current group
					set tags of newRecord to (item 2 of thisData)
				end try
			end repeat
		end if
	end repeat
end tell

Note the title is picked up by the process. If you want to use the title in the sheet, that’s certainly possible.

Also note commas are tag delimiters in macOS’ token fields now. This code is actually taking advantage of that to create separate tags without having to parse the tag column.

PS: This is not doing any URL validation, etc. It’s expecting valid URLs.

This worked perfectly. Spectacularly helpful. THANK YOU!

Regarding this

… just curious: what makes this a “dangerous” thing to do?

Again - THANK YOU for saving me many many hours of further searching and scripting experiments. :slight_smile:

You’re very welcome.

… just curious: what makes this a “dangerous” thing to do?

Just teasing you about assuming things. :slight_smile:

1 Like

Hi, I’m new to DT—coming from Windows to Mac, with a handful of csv’s from other apps (pocket included) I’d like to import. Could you point me to some 101 information about how to use scripts like the one above? Thanks!

  1. On the Mac, open /Applications/Script Editor then copy and paste the code above.
  2. Select Script > Compile.
  3. If it compiles successfully, select the sheet in DEVONthink.
  4. In Script Editor, select Script > Run.

Do not do this on all the files, test it out to see what happens. As Ihave no idea about your particular situation, I can’t comment on the results.

If this is something you will use often, you can save the file to ~/Library/Application Scripts/com.devon-technologies.think3/Menu.

1 Like