Hello,
I am totally new to devonthink and I just migrated my evernote notes into it and I am really loving it so far 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?
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?
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.
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 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
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.
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.
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:
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.
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.