Tips: Insert video into markdown notes

Hi there~

It seems that no one in the community has shared the content about how to insert audio and video into Markdown notes?? :thinking: I searched for the keyword “markdown” and “video”, but I didn’t find the relevant content…

Recently I found a method of inserting online video into markdown file on the Internet. After testing, it is still available after replacing the network address of the video with the DT file link.


Insert the file link of the cover in position 1
Insert the file link of the video at position 2
and then:

Maybe this is the basics of markdown syntax and I don’t know if I’m the only one who just learned about this. :stuck_out_tongue_closed_eyes: For me this is quite useful, I like to insert some videos in the notes of life record.

So if you already know this method, two small questions for you:

  1. Can anyone write a script to generate a video markdown link?
  2. If I insert a photo into Markdown, then the width and height of the photo can be changed according to the size of my editing window, but if I insert a video, it does not work, I wonder if this can be set?
1 Like

It’s the basic of HTML syntax (HTML5, I think). It has nothing to do with Markdown as such. MD just accepts HTML elements and some of the MD processors might even honor <video> etc. Personally, I wouldn’t rely on it. But then I don’t need video anyway.

As @pete31 said in the other thread: you should learn AppleScript (or JavaScript, or both) and write your own scripts.
I might add: Or pay someone who does it for you.

As I said before, this is HTML syntax. It has nothing to do with DEVONthink not Markdown. HTML is explained over at Mozilla developer network (MDN) and a lot of other places in the web.

1 Like

Here is a teaching edition example of creating the HTML links…

tell application id "DNtp"
	set URLList to {} -- Start an empty list
	
	repeat with thisRecord in (selection as list) -- Loop through the selected items.
		set recordType to (type of thisRecord as string) -- Put the type of the record into a variable
		if (recordType = "quicktime") then -- Check if the record type is video (or audio actually)
			set recordLink to (reference URL of thisRecord as string) -- Put the item link in a variable
			copy ¬
				("<video controls=\"\"> <source src=\"" & recordLink & "\"></video>  " & return) to end of URLList
			-- Construct the HTML link, including the item link and copy it to variable for the list of URLs 
			-- Note double quotes have to be escaped. Otherwise they would close a quoted section of text.
		end if
	end repeat
	
	if URLList ≠ {} then -- Check the variable for the list of URLs. If it's not empty copy the list as a string to the clipboard.
		set the clipboard to (URLList as string)
	end if
end tell

And you can add CSS styling for the video element to adjust it’s dimensions, e.g.,…

video {
width: 95vw;
height: auto;
margin:  10px 0;
}

Shouldn’t that be thisRecord instead of therecord?

Yep. Thanks.
I was modifying it to show another basic step and variable use.

Fixed.

Thanks for your reminder, I’ll start learning about them. Apologize for my rudeness and ignorance. :sob:

Thank you so much!! For your help and patience!!!

No worries!
Check out the Automation chapter in the Help. It covers more than just AppleScript.

Start with something simple like showing a dialog box to enter a name that will create a group with that name.

Also, I often use the term ”teaching edition” in scripts for the forums. The scripts in the posts are written in a simpler, beginner fashion and usually commented so explain some of what’s happening.

And remember, automation is not the answer to everything.

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