Download youtube video automation

Hello,
I am totally new to devonthink and I just migrated my evernote notes into it and I am really loving it so far :slight_smile: I am encountering new features which evernote was lacking every day and I was wondering if I finally can have the “feature” which I was not able to have before.

I would like to clip a youtube bookmark from the browser and IOS. Devonthink on my mac should then download the video if it is a youtube link via youtube-dl and store it into a specific database.

Can such behavior be realized with Devonthink? And if so how? :slight_smile:

Thanks.

2 Likes

so I guess smart rules in combination with running an applescript is the solution. Are there any good docs who explain smart rules + applescript in depth?

There’s a short overview in the DT documentation (cf. “Automation”). Apart from that, you’ll find lots of scripting examples in the forum.

Welcome @KaputtZimon

There is no built-in integration with youtube-dl but as @chrillek noted, you could potentially script this.

thanks for the reply. I skimmed through some examples however I am not clear how to call youtube-dl in an applescript with the url of the record and how to get the output into devonthink.

You’d have to use a do shell script command but I’m not at my Mac right now and I don’t use that particular util.

thanks, yea its basically more a general question:
How can I pass a parameter (the url of the record) to a command line programm and get the output (mp4 file) into devonthink in a apple script which can be used in a smart rule.

Did you actually try to pass something similar to
run shell command from AppleScript
in your web browser’s search field? That might provide more sensible information than you could get here by reiterating the question.

I had to call a shell script in the script I posted here.

I did so using set CheckSum to do shell script "/usr/bin/openssl sha1 " & quoted form of thePath so I’m guessing what you are looking for will be do shell script "path/command " & quoted form of *variable containing the instruction for getting the video* & "path to your global inbox"

That’s assuming your command wants input along the lines of command URLofVideo [switches] path to folder video should be saved in

Presumably the URLofVideo can be extracted from the bookmark? So you’d do something along the lines of set theURL to thebitoftheURLwhichyouwant, either using regex or if the basic URL format is always the same, using offset and/or texts.

The path to your global inbox will typically be /Users/USERNAME/Library/Application Support/DEVONthink 3/Inbox.

You’ll find the forum quite helpful when you’ve put together your first attempts and get stuck :slight_smile:

1 Like

Thank you all. I guess I will have to spend some time with apple script until I can give it the first try.

Just as an aside: you could use JavaScript as well, if you’re more comfortable with that.

that is a good tip thanks! I would actually prefer javascript. I am not clear how to embed this, but I hope I can find some guides

There’s a thread on the use of JS in smart rules. It is a bit contrived, but works in many cases. The basic structure looks like this

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
// Do something with the array of records, presumably in a records.forEach(...)
}

(() => {
  const app = Application("DEVONthink 3");
  performsmartrule(app.selectedRecords());
)}()

The self-executing function at the end permits you to test the script in script editor. AND it makes sure that DT runs it as an external script. Don’t ask me why that’s necessary, it just is. Also, you’ll see a message stating that DT encountered “Error: Error: No Error” with your script. This is a relict from philosophy 101.

1 Like

thanks. Is there some documentation / reference somewhere? What member does app has?

And what script editor where you referring? Does devonthink has its own script editor? Or did you mean just “any” script editor so that basically you can test without having to runs a smart rule with the script?

I think I just need a documentation and some samples then I am good to go.

you guys really helped so far.

Script editor (the one from Apple, preinstalled), select function library from the file menu and then DEVONthink. Switch from AppleScript to Javascript in the top left. And start weeping. Unfortunately, that’s the only documentation there is.

In the forum. Searching forEach should give you some hits. Also searching for tell application will lead you to a lot more AppleScript examples.
tell application is the equivalent of const app=Application() and calling methods on the app object. The tell thingy basically sets the context for the following method calls in AppleScript.

ah thanks its File->Open Dictionary->Devonthink. that is the documentation I was looking for.
However I do not get a simple example running which just displays something.
When I just add your code I get a syntax error everytime I want to save. And when I try this:

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  app.displayAlert("hello world");
}

The log tells me: Error:Error:Message not understood and no alert is popping up : /
I am doing somehting wrong here.

I also tried this:

function performsmartrule(records) {
  let app=Application("DEVONthink 3");
  records.forEach(r => app.logMessage(r.plainText()));
}

The first example can’t work because displayAlert and some other display methods are only availabe after having
app.includeStandardAdditions = true

Is this the complete script? How did you run it? Any messages? In the context I posted before, it works ok here.

Anyway, you might really, really want to use the search engine of your choice. Although there’s not a lot of JXA documentation out there, it is still helpful to read that. A starting point is this Mac Automation Scripting Guide: About Mac Scripting, then there are the release notes of OS X 10.10 and 10.11 with a very terse explanation of JXA conventions.

The problem here is that AppleScript is (my opinion!) a terrible language, wheres JS is resonably ok – but Apple abandonded it. As it apparently pretty much did the automation effort for recent app. Note the absence of the URL property in Reminders, the lack of useful scripting for Preview.

1 Like
function performsmartrule(records) {
  let app=Application("DEVONthink 3");
  records.forEach(r => app.logMessage(r.plainText()));
}

yes this is the complete script. I run it by creating a smart rule by adding it to a smart rule and hit “apply rule”.

The log shows me:
on performsmartrule (Error:Error:Message not understood).

I basically just want to get a “hello world” example running so I can start playing around with it.
I absolutely agree about your opinion of Apple Script and I really want to use javascript.
But for this I just need to get the minimal code running and go from there.

vs

I did not write these sentences without a reason. Nor did I mention this

out of sheer madness.

If you choose to ignore advice, that’s up to you. But I’m out of it now.

I am not ignoring any advice but maybe I was not communication well. Let me try to sum it up in the hope that you will reply.

As I mentioned, I also tried to add the self-executing function at the end you mentioned so therefore the complete script looked like this:

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  records.forEach(r => app.logMessage(r.plainText()));
}

(() => {
  const app = Application("DEVONthink 3");
  performsmartrule(app.selectedRecords());
)}()

However, as I mentioned, I can not save this in the Script Editor because this gives me a syntax error:

Error on line 9: SyntaxError: Unexpected token ‘)’

Also as you can see, I am not using any display methods since I read your comment about it, I am only logging.

I hope this was more understandable now, and I apologies if I was not clear enough