Is there a way to export all source URLs from a given set of documents? Not the URLs in the documents, but the actual source in the Generic panel. My end goal is to create a workflow for quickly creating a series links that i can then format as a citation for references in my writing.
Tools > Create Table of Contents ?
A script can do that. Something along these lines (JavaScript)
function performsmartrule(records) {
const app = Application("DEVONthink 3");
const linkCollection = app.createRecordWith({name: "URL collection", type: "text"});
const URLSet = new Set([...records.map(r => r.url()).filter(url => url.length)]);
linkCollection.plainText = Array.from(URLSet).join('\n');
}
This is written to be used as a JavaScript script in a smart rule. It grabs all URLs from the records selected by the smart rule conditions and writes the unique (!) ones in the new text document “URL collection” in the global inbox.
This sounds promising. Forgive my ignorance, but how would i add this? I assume new smart rule, but beyond that, I’m lost as to where i could input the javascript.
I’m looking to do this on a set of documents that all have the same tag.
Ahh, gotcha.
But what are you actually doing with the URLs? You apparently have no process yet so it’s not possible to provide more than a cursory example.
Forgive my laziness, but that
- is explained in the documentation (check out the section on “Automation”)
- has been discussed ad nauseam here
I don’t see any point in repeating all that has been said about it.
The idea would be to take all source URLs as the basis to then use a formal citation style (Chicago, for instance). So just a simple exportable list.
Just not a programmer, and don’t immediately see a straightforward way to implement what you’ve said.
- Open /Applications/Utilities/Script Editor.app.
- Paste the provided code. If using @chrillek’s code, also change the language dropdown to JavaScript.
- Make sure to select View > Show Log, if the log at the bottom of the script window is not showing.
- Select and item with a URL in DEVONthink then select Script > Run in Script Editor.
If you want to save this script…
- Select File > Save.
- In the Save dialog, press Command-Shift-G and paste ~/Library/Application Scripts/com.devon-technologies.think3/Menu. You can save into that directory or a subfolder of your choice.
- Give the script your desired name and save it. The script should now be available in the Scripts menu in DEVONthink.
thank you very much - i’ve been able to accomplish this but it doesn’t seem like @chrillek’s script is accomplishing anything?
It should create a plain text document with the URLs. However, @chrillek would have to comment on his code.
Here is a similar AppleScript version though it doesn’t filter for unique URLs…
tell application id "DNtp"
if (selected records) is {} then return
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set allURLs to (URL of (selected records))
set allURLs to allURLs as string
set AppleScript's text item delimiters to od
set urlDoc to create record with {name:"URL collection", type:text, content:allURLs} in incoming group
end tell
You’d need to make sure the language is set to AppleScript. This makes a plain text document in the Global Inbox.
this worked! thank you so much i appreciate you!
Err… That is not how a smart rule script is used or installed.
@jadecricket: You don’t need to be a programmer to read and follow the instructions in the manual. Anyway:
- Create a smart rule that selects the files you want to use
- Select the action “Execute script”, choose “JavaScript” and “Edit script”
- in the pop-up that opens, overwrite all the code with what I posted
- Leave the rule’s trigger on “manual”
You can then run the rule manually from its context menu in the sidebar.
Correct as a smart rule is only one approach. I opted for a standalone script.
As a clarification: my instructions regarding @chrillek’s code were incorrect. His is a smart rule script that would be installed in a different directory to run as an external JavaScript or to be pasted/entered into the smart rule as an embedded script. Apologies for the oversight.
Is the URL you’re interested in the one that appears in the URL column when you’re viewing items as a list?
If so, Tools->Create Metadata Overview will give you a tab separated values file with metadata for selected items.
The scripts are cooler, obviously!