Is That Possible to Trigger a Macro When a File Is AirDropped?

I would like to create a macro that runs when file(s) are AirDropped to macOS or if not possible to monitor the ~/Downloads directory and open the Finder highlighting the new files.

Is that possible?

Short answer: no.

What is it exactly you'd like to do? There may be another way.

You can monitor the Downloads folder, and when a new file is added, reveal it. The sample macro below should do that for you. This does not target files sent specifically via Airdrop per se, but it might at least help with what you’re doing.

Like @noisneil said, if you can provide us more context, we can help out some more.

Reveal newly added file to Downloads directory.kmmacros (3.3 KB)

Macro screenshot (click to expand/collapse)

1 Like

This will work if you're airdropping files from another of your own devices; from anyone else, you'll need to find a way to auto-accept the file too. I found an applet that will apparently do that, so you might be able to adapt it.

Of course, any file added to Downloads will trigger the macro, so you might want to set up a dedicated Airdrop folder too.

If you don't want to set up another folder for Airdrop you can use the fact that Airdrop applies its own "quarantine" flag to files (see So you could trigger a macro every time something is added to Downloads, check the quarantine flag, and immediately exit if it wasn't Airdropped.


Thanks for the script. The script opens the Finder but does not highlight the new files.

If I add a display text %Variable%local__file% in the loop it shows the name of other files.

For example: I drop 5 files and it shows 2 other files that have no relation to the ones dropped...

Open Finder revealing all new files dropped to ~/Downloads.

@cdthomer posted a script that opens the Finder but reveals the wrong files.

For testing, try adding a 1 minute pause as the first action in the macro and see if that helps. My guess is that the macro is being triggered when the file is dropped, but Airdrop doesn't use a partial file naming convention that KM can recognise. So the file listing is being done too soon and your new files aren't being included in it.

Thanks. Adding a 2 second pause helps a little. Now, if I drop, let's say, 5 files, one of them is highlighted, not all files.

In fact the one highlighted is the last one in the group.

What do you mean by

Airdrop doesn't use a partial file naming convention that KM can recognise


When the file is dropped an invisible file is created while it's uploading and then it's renamed when the upload is completed.

So – for each uploaded file you get at least two changes that trigger KM's folder trigger.

To see this in action save all the file paths from the macro and look them over.

Folder Trigger ⇢ Test.kmmacros (3.0 KB)
Keyboard Maestro Export

When downloading a file in Google Chrome I get two activations:

Folder Trigger ⇢ Test

Folder Trigger ⇢ Test

This temp-file to renamed-file methodology is pretty common and the major pitfall to using Keyboard Maestro's Folder Trigger.

It's easily worked around, but you have to understand what's happening.

When you add a file to a "watched" folder, your macro is triggered. If you drop in 5 files your macro is triggered 5 times, once for each. See this Wiki page.

That page also explains how KM makes its "best guess" at whether a file has completely downloaded or not -- a best guess that probably doesn't work with Airdropped files. I think that what you are going to have to do is:

  1. Trigger the macro when the file starts to arrive
  2. Use the path in the TriggerValue token to pause until the file has finished copying, probably using lsof to check if the file is no longer open
  3. Do whatever action(s) come next

And the above will happen, independently, for each file that gets Airdropped -- it won't be one run for a "batch" of delivered files. At that point you are probably better off setting your Airdrop folder to somewhere other than Downloads -- how/when you process that folder's contents will very much depend on what you are trying to achieve.

So what are you going to do in your macro once the files have arrived?

I see thanks. It is like saving in atomic mode, first save it on a temporary file, then rename it.

Is there any script you know, already created, that detects and avoids that?

There are some, but I'm not going looking...

In general all you have to do is use an IF with a text condition and make sure the file name doesn't start with a dot.

My problem is that when I airdrop a bunch of files to Download, Airdrop requires me to select show file to see the files when I do, the files are not highlighted and I have to guess their names and find them in a list of a gazillion files, because my Downloads directory has a lot of crap. It annoys the hell out of me.

Sort your Downloads folder by "Date Added" and the files will always be at the top...

The script @noisneil linked to earlier automatically moves Airdropped files to a folder of your choice, which might help. You'll see it does use the "quarantine flag" to differentiate between downloaded and Airdropped files and doesn't make special allowances for changing names during the Airdrop delivery. But if you want to highlight all the files just Airdropped you are going to have to find a way to batch the files arriving, wait until all but one of the triggered macros have finished, then tell the Finder to select multiple files.

I'd definitely go with the "sort by date added solution"!

I have no clue how to do that, but I will try. Thank you guys!