Generate item link for all documents in a folder

Hi,

I am looking for a way to automatically generate item links to all documents insides one particular folder.

The use-case is a folder with reading material for which I would like to create a “Things 3” check-list with direct pointers back to devonthink.

And what kind of input would Things 3 be expecting?

Basically I am looking for a way to generate these “Copy item link” automatically …

Something like

x-devonthink-item://187BCC66-78ED-46C7-B2F7-4091F3E8A8E0

That would be the input I would like to get into things3, but for all objects/files in one folder.

Let us say there are 100 PDFs, i would be expecting something like:

x-devonthink-item://001

x-devonthink-item://100

I understand what links you need but you need to know about Things’ input needs (if it’s even possible).

Getting a set of links will be of no help unless you know the input Things requires.

In the easiest form, I will be sending the result of this process via email into Things (Things has an incoming email feature).
I.e. Things’ Input will be 1:1 the list of the x- // links.

Assuming Things.app can handle more than one line in an email you could try this.

-- Get Reference URL of children as string list

tell application id "DNtp"
	try
		set theRecords to children of current group
		
		set theRefURLs to ""
		set theRecordsCount to (count of theRecords)
		set theCount to 0
		
		repeat with thisRecord in theRecords
			set thisURL to reference URL of thisRecord
			if theCount = 0 then
				set theRefURLs to theRefURLs & thisURL
			else
				set theRefURLs to theRefURLs & return & thisURL
			end if
			set theCount to theCount + 1
		end repeat
		
		set the clipboard to theRefURLs -- don't know if Things.app supports AppleScript  
		
		#return theRefURLs -- testing
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
1 Like

Rock&roll, pete31! Thanks a ton for your script. Works as intended:

Two additional questions:

  1. What would be the step to add to generate a text file with the result of the script i.e. with “theRefURLs”?
  2. Is there an easy way to include the name of the file into your script so that is shown after the x-devonthink link?
-- Get Reference URL of children as string list

tell application id "DNtp"
	try
		set theRecords to children of current group
		
		set theRefURLs to ""
		set theRecordsCount to (count of theRecords)
		set theCount to 0
		
		repeat with thisRecord in theRecords
			set thisURL to reference URL of thisRecord
			if theCount = 0 then
				set theRefURLs to theRefURLs & thisURL
			else
				set theRefURLs to theRefURLs & return & thisURL
			end if
			set theCount to theCount + 1
		end repeat
		
		set newTextRecord to create record with {name:"newText", type:text, content:theRefURLs} in current group
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

If you want “[Reference URL] space [Name]” this should work

tell application id "DNtp"
	try
		set theRecords to children of current group
		
		set theRefURLs to ""
		set theRecordsCount to (count of theRecords)
		set theCount to 0
		
		repeat with thisRecord in theRecords
			set thisURL to reference URL of thisRecord
			
			set thisName to name of thisRecord
			set urlAndName to (thisURL & space & thisName)
			
			if theCount = 0 then
				set theRefURLs to theRefURLs & urlAndName
			else
				set theRefURLs to theRefURLs & return & urlAndName
			end if
			set theCount to theCount + 1
		end repeat
		
		set newTextRecord to create record with {name:"newText", type:text, content:theRefURLs} in current group
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell
1 Like

Awesome, pete31! That works - provides a really nice integration between things3 and DT3/DTTGO.


P.S.: I think it time for me to finally learn applescript :slight_smile:

I will try to see how I can use your code as a basis of the workflow in keyboard maestro and will be sharing the results later.

1 Like

How to turn on this “incoming email” feature in Thnigs3?

Thx

Check this out, Hens. Basically, you need to click " Mail to Things" in settings and get your own things alias. As I do not use a Mac app for things, I built a keyboard maestro script which allows me to mail stuff into things. In this case, this will be a list of devon links …

I see.

You can also use Popclip’s extension for Things 3.

Highlight the List then popclip pops up and send it to things, works the same way :slight_smile: