Questions on possible use-case in academic environment (law)

Hi @wrothnie

Sure - here’s the script:

-- produces list of case names with citations for selected authorities
-- assumes custom metadata fields "Citation" for reported citation (eg [2019] 4 All ER 745) and "Neutcite" for neutral citation (eg [2017] UKSC 59)
-- assumes empty custom metadata fields for Citation & Neutcite have been prepopulated with underscore (ie "_")

tell application id "DNtp"
	try
		set the clipboard to ""
		
		set theSelection to the selection
		
		repeat with thisRecord in theSelection
			set caseName to the name without extension of thisRecord
			
			set theURL to reference URL of thisRecord
			
			set customMD to custom meta data of thisRecord
			-- get reported citation if available
			set mdCitation to (mdCitation of customMD)
			if mdCitation is "_" then
				set reportedCitation to ""
			else
				set reportedCitation to mdCitation
			end if
			-- get neutral citation if available
			set mdNeutcite to (mdNeutcite of customMD)
			if mdNeutcite is "_" then
				set neutralCitation to ""
			else
				set neutralCitation to mdNeutcite
			end if
			
			-- set result depending on whether values empty
			-- (a) case name
			if reportedCitation is "" and neutralCitation is "" then
				set theCitation to ""
				display alert "DEVONthink" message "No citation or neutral citation for " & caseName & " in Devonthink" as informational
				-- (b) case name + reportedCitation
			else if reportedCitation is not "" and neutralCitation is "" then
				set theCitation to reportedCitation
				-- (c) case name + neutralCitation
			else if reportedCitation is "" and neutralCitation is not "" then
				set theCitation to neutralCitation
				-- (d) case name + reportedCitation + neutralCitation
			else if reportedCitation is not "" and neutralCitation is not "" then
				set theCitation to reportedCitation & "; " & neutralCitation
			end if
			
			-- display alert "DEVONthink" message "Citation copied with link for " & caseName & " in clipboard" as informational
			
			set the clipboard to (the clipboard) & "[" & caseName & "](" & theURL & ")" & " " & theCitation
			
		end repeat
		
	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

Here’s the previous post I adapted it from (thanks go to @bws950 & @pete31).

Caveat: I’m not very good at scripting - bluefrog would probably be able to do something in 3 lines which does all the above and pete31’s would additionally draft the legal submission and lodge a notice of appeal. :stuck_out_tongue_winking_eye:

The reason for the “if … mdCitation is “_”” line is so that it returns only the neutral citation if the case hasn’t been reported.

bws950’s version is a bit more sophisticated in that it has separate metadata fields for the court and first page, whereas mine lumps them into the one field, so that I can copy and paste it in one hit. You could probably do a smart rule with a regex search on the content (a bit like @chrillek’s date regex (which is very cool)) to pull that from the documents and automatically put it in the citation fields but it would likely be a bit hit and miss with some of the poorer quality older scanned reports.

If you want to have a version which copies the citation without the link (so that you don’t have the link cluttering the citation when you are pasting into a Word document, for example), you can change “set the clipboard to (the clipboard) & “[” & caseName & “](” & theURL & “)” & " " & theCitation” to

set the clipboard to (the clipboard) & " " & caseName & " " & theCitation

A question for @bluefrog or pete31 which has been niggling at me for some time is whether there is a workaround to avoid the script failing if the custom metadata field is empty. My current workaround is to have a smart rule that pre-populates the custom metadata fields with an underscore on importing the file into my inbox, but if I didn’t have to do that it would save a step and simplify the script.

Best of luck with it. :slightly_smiling_face: