Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Folder Action script written in AppleScript used to separate AirDropped files into a different folder other than the default Downloads folder
property AIRDROP_FOLDER : "Path:to:AirDrop:Folder:in:Alias:format"
property QUARANTINE_KEY : "59"
property GET_QUARANTINE_COMMAND_START : "ls -l -@ '"
property GET_QUARANTINE_COMMAND_END : "' | tr '\\n' ' ' | sed 's/.*com\\.apple\\.quarantine\\s*\\(\\d*\\)/ \\1/' | awk '{$1=$1};1'"
on adding folder items to this_folder after receiving added_items
repeat with i from 1 to length of added_items
set current_item to item i of added_items
set quarantine_type to getQuarantineType(POSIX path of current_item)
if quarantine_type is equal to QUARANTINE_KEY then
moveFile(current_item, alias AIRDROP_FOLDER)
end if
end repeat
end adding folder items to
on moveFile(move_file, destination_dir)
tell application "Finder"
move move_file to destination_dir with replacing
end tell
end moveFile
on getQuarantineType(file_path)
return do shell script GET_QUARANTINE_COMMAND_START & file_path & GET_QUARANTINE_COMMAND_END
end getQuarantineType
@PencilNotPen

This comment has been minimized.

Copy link

@PencilNotPen PencilNotPen commented Jan 2, 2019

This could be exactly what I'm looking for! Could you please tell me how to specify in the script which folder the Airdrop files should be moved to? How does it handle cases in which there is already a file in /Downloads with the same name as the file being Airdropped over?

Thanks so much!

@PencilNotPen

This comment has been minimized.

Copy link

@PencilNotPen PencilNotPen commented Jan 2, 2019

The script works really well, I managed to specify the folder. However, it overwrites files with the same name, which can be a problem. iPhone camera roll photos always name in the same way, which means that transferring photos over via AirDrop can overwrite them. Is it possible to check for duplicate filenames, and add a timestamp to them to differentiate?

@barfburglar

This comment has been minimized.

Copy link

@barfburglar barfburglar commented Jan 21, 2019

You can use Automator to do this...

Where "walkie talkie" is listed, you want to put the device name sending to your Mac, if it's multiple devices, just add another line with its name.

screen shot 2019-01-20 at 9 11 27 pm

@SoraAzure

This comment has been minimized.

Copy link

@SoraAzure SoraAzure commented Mar 3, 2019

Just forked and modified the code to rename the AirDrop files with a number suffix, if there's any file with the same name in target folder.

@misoastar

This comment has been minimized.

Copy link

@misoastar misoastar commented Oct 24, 2019

i have mojave 10.14.6 for me line

moveFile(current_item, alias NEW_AIRDROP_FOLDER)

doesn't work. no errors, just quit script. i just removed word "alias" and now it works:

moveFile(current_item, NEW_AIRDROP_FOLDER)
i set AIRDROP_FOLDER in same format:
property AIRDROP_FOLDER : "Macintosh HD⁩:Users⁩⁩:⁨⁩MyUserName⁩:Downloads:myAirDrop"

@sz8142

This comment has been minimized.

Copy link

@sz8142 sz8142 commented Nov 13, 2019

i have mojave 10.14.6 for me line

moveFile(current_item, alias NEW_AIRDROP_FOLDER)

doesn't work. no errors, just quit script. i just removed word "alias" and now it works:

moveFile(current_item, NEW_AIRDROP_FOLDER)
i set AIRDROP_FOLDER in same format:
property AIRDROP_FOLDER : "Macintosh HD⁩:Users⁩⁩:⁨⁩MyUserName⁩:Downloads:myAirDrop"

Why I keep recieve the warning "error -1,752 " which tells me cannot save to file "airdropSorter.scpt"?

@misoastar

This comment has been minimized.

Copy link

@misoastar misoastar commented Nov 14, 2019

looks like Mac OS security reason. just save your script somewhere else (like desktop), then copy it from there to Library-Scripts-Folder Actions Scripts, OS will ask about your permission and you have to input your password. that's it.
I hope it helps.

@Peter-Schorn

This comment has been minimized.

Copy link

@Peter-Schorn Peter-Schorn commented Nov 26, 2019

I just set it up and it works. However, if I try to move an airdroped file back to my download folder, it gets automatically moved back to my airdrop folder. Can someone show me how to modify the script so that this does not happen? One idea is to add some metadata to the file after it has already been added to my airdrop folder once, and then files with that metadata can be excluded from the script thereafter.

@wmjlxl

This comment has been minimized.

Copy link

@wmjlxl wmjlxl commented Mar 3, 2020

hello, i am in catalina 10.15.3 and use this script.

it works but files will also save in default download foler. thats to say it will have two copies.

anyone know how to solve this problem?

thanks.

@UltraREX

This comment has been minimized.

Copy link

@UltraREX UltraREX commented Mar 26, 2020

I just set it up and it works. However, if I try to move an airdroped file back to my download folder, it gets automatically moved back to my airdrop folder. Can someone show me how to modify the script so that this does not happen? One idea is to add some metadata to the file after it has already been added to my airdrop folder once, and then files with that metadata can be excluded from the script thereafter.

It works.

@UltraREX

This comment has been minimized.

Copy link

@UltraREX UltraREX commented Mar 26, 2020

How to use it.

step 1:
cd ~/Library/Scripts
mkdir Folder\ Action\ Scripts # if 'Folder Action Scripts' folder does not exist

step 2:
create a file, name it xxxxx.scpt
then copy all scipt into xxxxx.scpt

step 3:
right click Downloads folder, select Services -> Folder Action Steup
Enable Folder Action
Add Downloads on the left panel
Add xxxxx.scpt on the right panel

@Mr-UFO

This comment has been minimized.

Copy link

@Mr-UFO Mr-UFO commented Jun 10, 2020

Thanks! This is exactly what I need! :)
However there's a BUG when transferring a bigger file more than 1 GB, it cannot be moved to the folder I need.

It runs well for the smaller files less than 200MB.

I will attach my screenshot.

PS: My system is 10.15.5
Snipaste_2020-06-10_23-50-16

@misoastar

This comment has been minimized.

Copy link

@misoastar misoastar commented Jun 10, 2020

you have a bug with big file because it takes a lot time to move it, so you need to add delay to this script

@teeeb

This comment has been minimized.

Copy link

@teeeb teeeb commented Nov 30, 2020

Hey Guys,
anyone have an idea how to that code to be able to choose a folder every time I receive a file from airdrop? I would like to be able to do Save As, and choose the folder. In fact, I would like to avoid having to send pictures and videos to my Mac to then transfert it to a Backup drive, that way I would be able to send by airdrop directly to a drive connected to my Mac. Can you help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment