DEV Community

Yufan Lou
Yufan Lou

Posted on

Change Destination Directory of AirDrop on macOS

You can't.

But there is a workaround, that is moving the file received by AirDrop from Download to your desired destination automatically as it is received. We can achieve this using a Folder Action combined with some filtering thanks to a security feature provided by Apple.

A Folder Action is an Automator workflow which runs whenever a file is added to a folder. Automator is a graphical programming environment specifically for macOS applications. It is similar to Shortcuts (originally Workflow) on iOS, but much older.

The finished Folder Action looks like this:

Automator interface, showing a Folder Action containing three actions: Get Selected Finder Items, Run Shell Script, and Move Finder Items

The Automator parts are hopefully straight forward. Simply search for the corresponding actions and drag them over.

  • "Get Selected Finder Items" takes the files added to Download and feeds it to the
  • "Run Shell Script" action, which filters to only the files transferred by AirDrop, and passes those to
  • "Move Finder Items", where you can configure the destination of those files. I have added a new folder called "AirDrop" inside my Download folder for this purpose.

The shell script inside the "Run Shell Script" action needs a bit more explanation. The code is this:

for f in "$@"
    if [[ -n $(xattr -p $f | grep "sharingd") ]] then
        echo "$f"

With "Pass input:" on the top right corner of the action as "as arguments", the for loop goes through each file. For each file, we check its extended attribute with xattr and see whether "sharingd" is contained in it. If so we echo it, giving it to the next action to move, otherwise we ignore it.

The extended attributes (xattr) are extra metadata attached to files for various management purposes. In this case, is the xattr containing the quarantine level of a file and where it comes from. sharingd is the daemon responsible for handling AirDrop on macOS, and it attaches this attribute with its own name in it to every file it receives. This is why we can use the command above to tell whether a file is received by AirDrop.

  1. To test the Folder Action, I had to add a Get Specified Finder Items at the top, since I cannot use the actual folder event. Automator told me so when I clicked the Run button.

  2. The shell script uses zsh, which is default for macOS Catalina.

If you like this post please press the like button to let me know! Please also comment to let me know what I can improve!

If you'd like to donate, please donate to Wikimedia Foundation, to which I owe infinitely.

Top comments (2)

boettges profile image
Peter Böttges

I just found your post when searching for a solution to this problem that was bugging me for a long time. Thank you for the great explanation!
I actually didn't know that Automator scripts could be triggered automatically in background.

One minor improvement:
I added mkdir -p ~/Downloads/AirDrop to the script after the fi. This will create the AirDrop folder if it doesn't exist and the move item step won't fail. 👌

mark_scheer_01bbd69ff7a56 profile image
Mark Scheer

Thanks! This definitely solved my need. Prefer to just have files Airdrop directly to the desktop.

QUESTION: not a scripter so don't know how to do this, but when this script executes, it still opens (and leaves open) the downloads folder window on my desktop. Any idea if there's a quick addition to the script that either DOESN'T open the window, or automatically closes it behind itself when the script is finished executing?