Skip to content

Instantly share code, notes, and snippets.

@menushka
Created December 30, 2018 22:47
Show Gist options
  • 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
@OscardR
Copy link

OscardR commented May 5, 2025

In my case this script didn't work when setting it up as a folder action. Basically nothing happened when I received files via AirDrop. So what I did is convert it to a simple shell script that can do the same task. It has to be run on demand from a terminal but for my use case is more than enough:

#!/bin/bash
AIRDROP_FOLDER="${HOME}/Downloads/AirDrop"
QUARANTINE_KEY="59"

for file in ~/Downloads/*; do {
  quarantine_type="$(ls -l -@ "${file}" | tr '\n' ' ' | sed 's/.*com\.apple\.quarantine\s*\(\d*\)/ \1/' | awk '{$1=$1};1')";
  [ "${quarantine_type}" = "${QUARANTINE_KEY}" ] && {
    echo "Moving '${file}' to AirDrop folder...";
    mv "${file}" "${AIRDROP_FOLDER}";
  }
} done

you can put it in your path and run it every time you want to clean up your Downloads folder 👍

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