Skip to content

Instantly share code, notes, and snippets.

@menushka
Created December 30, 2018 22:47
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save menushka/cb3ed28b73fc030b5b21e0316d059928 to your computer and use it in GitHub Desktop.
Save menushka/cb3ed28b73fc030b5b21e0316d059928 to your computer and use it in GitHub Desktop.
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
@UltraREX
Copy link

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

@FuckBound
Copy link

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
Copy link

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
Copy link

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?

@luckykamon
Copy link

Thanks, your script run on: Apple M1 Pro ; 13.0.1 (22A400)

@UnusualAppleScript
Copy link

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

I'm new here and I face the exact same issue as @FuckBound. Saw you mention on adding delay to this script. Can I ask how to go about? How will the additional code look like?

@rnag
Copy link

rnag commented Feb 27, 2024

This script works for me. I just needed to remove word "alias" as others mentioned.

Steps:

  1. open app "Script Editor", File > New, then paste contents and name as airdropSorter and save to ~/Desktop (default location)
  2. Modify script value AIRDROP_FOLDER to point to new location for airdropped files. Example: Macintosh HD⁩:Users⁩⁩:⁨⁩ritvik:Git-Projects:Personal:blah
  3. Remove alias so we end up with moveFile(current_item, AIRDROP_FOLDER)
  4. Run the following in a Terminal (enter password if prompted):
    sudo mkdir -p "/Library/Scripts/Folder Action Scripts/" && sudo cp ~/Desktop/airdropSorter.scpt "/Library/Scripts/Folder Action Scripts/"
  5. Right click on Downloads in Finder, Show In Enclosing Folder then right-click on Downloads and Services > Folder Action Setup and make sure you got "Downloads" on left and "airdropSorter" script on right, and everything is checked.

Tested on:
Apple M2 2023; Sonoma 14.2.1 (23C71)

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