That would be a question for Paul Kim, aka Mr. Noodle, over at Noodlesoft.
This is an unusual place for your system downloads to point to. Can you clarify why you chose this location?
This is actually my system download folder, I set it there for better management of files
I set it there for better management of files
In what way? Iâm trying to understand some of your thought processes.
the html files can be matched and moved by Hazel perfectly, yet the url is not reset correctly, which is the thing my script tries to do.
you may have heard about the P.A.R.A management system, which inspires my file management system. I have inbox, projects, area, resources, and archive folder in my Documents folder, and using an app named Unclutter, the Inbox folder locates right on the top of the screen once you drag down from there, as you can see in the photo, for accessing the new files easier.
Without further ado, a solution in JavaScript
const ChromeExecutable = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
const baseCMD = `PATH="/usr/local/bin:$PATH" ; single-file --browser-executable-path "${ChromeExecutable}"`;
(() => {
const chromeApp = Application("Google Chrome");
const DTApp = Application("DEVONthink 3");
const curApp = Application.currentApplication();
curApp.includeStandardAdditions = true;
// tell application "Google Chrome" to return URL of active tab of front window
const url = chromeApp.windows[0].activeTab.url();
const title = chromeApp.windows[0].activeTab.title();
const targetFile = `/tmp/${title}.html`;
const shellCmd = `${baseCMD} ${url} "${targetFile}"`;
console.log(shellCmd);
curApp.doShellScript(shellCmd);
const record = DTApp.import(targetFile, {to: DTApp.databases['Test'].incomingGroup()});
record.url = url;
})()
It saves the active tab of Chromeâs top most window to a file in /tmp
and then imports that into the database Test
âs inbox. The title of the HTML page is used as file name.
I omitted the removal of the file from /tmp
as well as cleaning up the file name to remove unwanted characters.
This approach has several benefits:
- The script is short and sweet.
- It doesnât rely on UX scripting (which is really the worst part of scripting)
- It doesnât rely on timeouts which are not reliable and not state of the art
- It does what you want (dwyw): Save the stuff to DT with the URL set to the original one
omg thank you so so much!!! still a little confusing, do I still need to use Hazel to run the script, or in what way, as the script can be a little bit obscure for me.
i now use the Microsoft Edge as my primary web browser, how can the script still work for Edge?
You find this script âobscureâ, after all the fiddling with function.bind
in yours? Nice joke.
Anyway, you can put it in a file and then
osascript -l JavaScript file
in Terminal. Or run it from Script Editor, or Visual Studio Code, or CodeRunner or whatever.
No, Hazel is not involved. Why would it be? The script already does all the importing and stuff (as mentioned in my post, btw).
Why does it matter which browser downloads the document, as long as itâs downloaded?
The SingleFile CLI is well-documented, and since Edge is only another incantation of Chrome, I suppose that changing the path to ChromeApp
might be sufficient.
Just forgive me for my illiteracy of codes Thatâs all my fault as I have actually no knowledge of programming except the most basic parts of syntax
You were delving deep into the abyss of JXA-ObjC with your script, so I assumed that you had a very good grip on JavaScript etc. Where did you pick up that timer stuff then? Iâm curious because I havenât seen any examples of passing blocks to ObjC methods from JavaScript until now.
So I can also put it in Alfred, Keyboard Maestro or any application like that, and set a shortcut to run the script?
That part of script is copied from the Internet
URL?
you mean which part is copied? certainly the timer, I cannot understand even a single line of that part, I just copy it into my script and surprised to find it works well
Certainly~ just limited to programming capabilities and donât have good ways to do the same stuff.
- Index the Downloads folder youâre using. I called mine
Doc Downloads
as a temporary measure. - Then create a smart rule with a small bit of AppleScript in it, like soâŚ
Now if I clipped a SingleFile, it would go into this directory, and the smart rule would change the URL automatically. No Hazel, no JXA, and a simple, easy to read bit of AppleScript.
Here is the smart rule:
Reset SingleFile URL.dtSmartRule.zip (1.6 KB)
Unzip it, then double-click to install it.
Then Control-click it and set the group to target.
Could u please put the Apple Script on the post, thank u so much!