Tips: Insert video into markdown notes

In fact, I’m reading dt’s help manual and trying to learn AppleScript, but due to some language and knowledge barriers, the pace of learning is a little out of keeping pace with my needs… :see_no_evil: Dt is really a software with unlimited possibilities, this community also brings me a lot of help, so trust me, I do not want to cause trouble for everyone, if I have something wrong please tell me straight.

Start small and simple, like the example I mentioned.
Like any language, it takes time to get used to. However, it’s still not out of reach for beginning coders.

And don’t forget there are things that can be done with smart rules and Tools > Batch Process.

Okay, thank you for your patient answers :rose:

You’re welcome :slight_smile:

Ahh sorry for the last question :sweat:, is “Quicktime” a type that includes video and audio?

If I want to create a link for audio file, like this <audio controls=""> <source src="XXX"></audio> and for video file, like this<video controls=""> <source src="XXX"></video>

How should i distinguish it

I don’t see a way. QuickTime is (was?) Apple’s media player/streaming server concoction. Since DT offers only this type (which I think is a misnomer), it probably does not differentiate between video and audio. You could try using the file extension or the command line tool file.

Thank you for your guidance. I tried to write a version based on @BLUEFROG that can distinguish pictures, videos, and audios. Maybe most of you can write such a simple script, but I still share it here, I hope it will be useful to someone. :stuck_out_tongue:

tell application id "DNtp"
	set URLList to {}	
	repeat with thisRecord in (selection as list)
		set recordName to (name of thisRecord as string)
		set recordType to (type of thisRecord as string)
		set recordKind to (kind of thisRecord as string)
		set recordLink to (reference URL of thisRecord as string)
		if (recordType = "quicktime") then
			if (recordKind = "MPEG-4 movie") or (recordKind = "QuickTime movie") then
				copy ¬
					("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "<video controls=\"\"> <source src=\"" & recordLink & "\"></video>  " & return & return) to end of URLList
			else if (recordKind = "MP3 audio") then
				copy ¬
					("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "<audio controls=\"\"> <source src=\"" & recordLink & "\"></audio>  " & return & return) to end of URLList
			end if
		else if (recordType = "Picture") then
			copy ¬
				("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "![](" & recordLink & ")" & return & return) to end of URLList
		else
			copy ¬
				("* [" & recordName & "](" & recordLink & ")" & return & return) to end of URLList
		end if
	end repeat
	
	if URLList ≠ {} then
		set the clipboard to (URLList as string)
	end if
end tell
1 Like

One note auf caution: recordKind could depend on the locale. So it might well be “MPEG-4 Film” on someone’s Mac running in the German locale.

Here’s a minor revision which does not depend on the version of macOS/Finder or the localization:

tell application id "DNtp"
	set URLList to {}
	
	repeat with thisRecord in (selection as list)
		set recordName to (name of thisRecord as string)
		set recordType to type of thisRecord
		set recordLink to (reference URL of thisRecord as string)
		if recordType as string is "quicktime" or recordType as string is "«constant ****quti»" then
			if width of thisRecord is greater than 0 and height of thisRecord is greater than 0 then
				copy ("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "<video controls=\"\"> <source src=\"" & recordLink & "\"></video>  " & return & return) to end of URLList
			else
				copy ("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "<audio controls=\"\"> <source src=\"" & recordLink & "\"></audio>  " & return & return) to end of URLList
			end if
		else if recordType is picture then
			copy ("* [" & recordName & "](" & recordLink & ")" & return & return & space & space & space & space & "![](" & recordLink & ")" & return & return) to end of URLList
		else
			copy ("* [" & recordName & "](" & recordLink & ")" & return & return) to end of URLList
		end if
	end repeat
	
	if URLList ≠ {} then
		set the clipboard to (URLList as string)
	else
		display alert "No items selected."
	end if
end tell
2 Likes

Thank you so much, I just wanted to say that after I moved the script I wrote from the Menu folder to the Toolbar folder, it couldn’t be used… :sweat:

But the strange thing is that when I execute the script you wrote for audio files and video files, The link on the clipboard doesn’t seem to be complete (Picture link can be obtained normally). Like this…

What is even more strange is I execute the script @BLUEFROG wrote for video files, The clipboard does not seem to be able to get the link successfully…Do you know why is that? :sweat:

It doesn’t make a difference whether it’s in the menu or toolbar over here, the conversion of the type to a string fails. The mysteries of AppleScript :thinking:

A workaround might look like this:

if recordType as string is "quicktime" or recordType as string is "«constant ****quti»" then

Hahahaha I really often encounter bugs! emmm, sorry… where should this line of code be added?

It should replace this line:

if recordType as string is "quicktime" then

:sob: it works! Thank you so much!

I’ve updated the above script, just in case that anyone else wants to use it.

1 Like

Yep, had a hard time figuring that out. Only happens with compiled/cached scripts.

Maybe a hint should be added to DEVONthink’s AppleScript dictionary?

And it doesn’t affect all types.

Where would be the best place?

record:

type get type3 The type of a record. HERE'S FREE SPACE, I think :)

Done.

1 Like