Watch downloads folder for PDF's and open with preview

Thanks to everyone for their suggestions. I’ve decided the easiest thing for me to do is embed the open in each individual script which downloads a pdf … after all, I already have the fully qualified file name there.

Larry

I am not completely following this, I have tried all sorts of things and this just opens the downloads folder and doesn't open newly saved PDF's in the downloads folder for me.

I don't think I understand what the trigger value is intended to do here.
https://wiki.keyboardmaestro.com/token/TriggerValue

As an aside, I use a piece of software called Hazel to do something similar. I've used it longer than I've had KM, and while I know KM can do this too, just throwing out alternatives. I use Hazel to processes all of my incoming scans from ScanSnap and sort them into the right folders, as Larry does with KM.

%TriggerValue% contains the thing that triggered the macro. Which means, in this case, the item that was added to the Downloads folder -> the downloaded PDF file.

I'm in the same boat as you on this one about 6+ years with hazel and only a couple years with Keyboard Maestro. I was thinking the same thing, that I should just do what I know and throw a rule into Hazel but thought I would learn something nice along the way. Ideal for me to keep all my rules in one place in a single macro if possible. Knowing myself I would look back on the Hazel rule and say this is silly why would I want that and delete the rule not realizing I use it for a macro that runs in Keyboard Maestro.

So what is the downloaded file any pdf file newly downloaded to the downloads folder? If that is the case I guess it just isn't working for me and just opening the downloads folder and showing me all my downloads. I'd probably be better off just using Comtion (Command+Option (⌥)) + L in Safari to show downloads and not have to sort the downloads. Or use this macro I made for that.

Show the Most Recently Downloaded File.kmmacros (45.1 KB)

Thank you both for the help so many great options.

This one will work:

The older macro a couple of posts above doesn’t work anymore because TriggerValue has been changed. (Formerly it contained only the last path component, now it holds the whole path. If I recall correctly.)

1 Like

@skillet, here is an additional macro that removes any PDFs from Downloads when you quit Preview. This way your Downloads folder becomes a cache folder for PDFs.

You can change the trigger to your liking (for example Periodic, or when Safari quits, or a combination).

Remove PDFs from Downloads.kmmacros (3.2 KB)

That makes a little more sense so the file itself wasn't being saved and only the full folder path.

The new macro works like a charm now. I changed if "any of the following are true" to "all of the following are true" but I can't really think of how any would cause other problems that I might not be thinking of but I did it to be safe and is working fine.[quote="Tom, post:17, topic:2837"]
You can change the trigger to your liking (for example Periodic, or when Safari quits, or a combination).
[/quote]

This is pretty awesome and the way you set it up for when Preview quits is perfect. For the previous macro to work the file can't already be in the folder because if you replace the file that is already there it doesn't trigger it as new so that is a great work around and keeps things from getting cluttered. What a great workflow!

Kind of scary to think of the dangerous things you could create with something like that. Close MS Word and remove all of my document files, yikes!

This is important when you have more than one condition.

If you download a PDF that is already present in the Downloads folder it will be auto-renamed, like this:

That means that the Folder Watch macro will trigger.

If the PDF was removed and is then downloaded again, the Folder Watch macro will also trigger.

To make it even more scary set the trigger to “Preview Deactivates”. This way the PDF will be trashed when you switch from Preview to another application (even without quitting Preview). Your Downloads folder is now a read-once cache for PDFs :wink:

Btw, the Trash action does not really remove your files. As it is set in the macro it just moves the PDFs to the Trash, as the name suggests. To delete the PDFs set the action to “Delete” (popup menu).

Not 100% sure I get what you're doing here, but you could have one macro trigger on file download, then activate another macro with a variable name based on the current year, pass a %triggervalue% argument to it... something like that. Then an if/then block on the macro that services the files could handle dispatching based on this variable.

Dear Chris,
Probably, I think that "Open Downloaded PDFs in Preview.kmmacros" is a macro created by you, so I will post from here.

I rewrote your macros a bit and made it possible to preview from "skim".
I specified the location of the file as "tutor UltraEdit_foler / master" Folder, which you recently gotten to consult.
When the number of files was small (content-1.tex to content-3.tex), there was not much problem, but as content-7.tex increased, 8 "pdf" created after LaTeX compilation was 8 , All will be displayed from "Skim".
What kind of writing should be done to ensure that PDFs from "content diverted" tex from content-1 to content-7 are not spit out?
How should only "main.pdf" (made from "main.tex") be displayed from skim?
Is there a way to specify the name?
I would be pleased if you teach me that way.

Thx and regards, WAKAMATSU (boehmflute)

Hey @boehmflute,

It sounds to me as if you're creating a batch of files at once to this watched folder.

If so I suspect you can do something like this:

image

-Chris

Dear Chris,
Thank you for your advice.
I have rewritten the point of your comment.
Thanks again, I was able to display only a specific "master.pdf".
By the way,I was not creating a batch of files at once to this watched folder.
Just I have changed Folder's path and Previewer app's from your original "Open Downloaded PDFs in Preview"macros.
Thx and regards, WAKAMATSU (boehmflute)
Open%20Downloaded%20PDFs

1 Like

This is awesome.

But I keep getting this path error

image

I double checked both of these:
/Users/macuser/Downloads/
~Downloads/

So %TriggerValue% is not working on my side somehow?

This macro/technique is in error.
==The %TriggerValue% returns the FULL PATH== to the item that was added to the folder.

So, it should be:

image

Most likely you are making the same error.
Just set the Open File to %TriggerValue%

1 Like

This macro should correct problems due to changes in KM and otherwise.
I'm not sure when the change occurred, but as of Keyboard Maestro 8.2.4, the ==%TriggerValue% returns the FULL PATH== to the item that was added to the folder.

Also, I have changed the original macro which open using default app to open explicitly using Preview.app, and only for files ending with (as opposed to contains) ".pdf"


MACRO:   Open Downloaded PDFs in Preview


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/f/6/f6049ef1c40c316c64e0aced22e88a91b6d50000.kmmacros">Open Downloaded PDFs in Preview.kmmacros</a> (2.7 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



![image|480x666](upload://o3vLhId6M0l8VoeZKfGsKPYHgbV.png)

Just curious...

Is there a reason you don't want to use a simple folder action to achieve this?
folderAct

Because I prefer to use KM, which is also simple.

But is there a way to extract just a filename from %TriggerValue% now when it returns the full path?

Easy - just use the Filter Action to get the file name component of the path. Check out the KM wiki here.

1 Like