How do I create an apple script that changes the destination folder of airdropped files?

If you are sure of the provenance of the AirDropped files and are happy to remove the quarantine extended attribute you can remove it as you say with xattr. In AppleScript you can do this using do shell script and passing the quoted path in alias form.

removeQuarantine(quoted form of (POSIX path of (current_item as alias)))
on removeQuarantine(file_path_alias)
    do shell script "xattr -d com.apple.quarantine " & file_path_alias
end removeQuarantine

In your script you want to call this before the file is moved so your script would look as below (remember to update the AIRDROP_FOLDER to your required path).

The script will now check files for com.apple.quarantine equal to 59 and if so remove the attribute before moving the file.

Therefore if you then move the file back to ~/Downloads it will not be moved again as the com.apple.quarantine attribute is no longer there.


property AIRDROP_FOLDER : "macOS:Users:hali:Desktop:Test"
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
            removeQuarantine(quoted form of (POSIX path of (current_item as alias)))
            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

on removeQuarantine(file_path_alias)
    do shell script "xattr -d com.apple.quarantine " & file_path_alias
end removeQuarantine

Note : This script will overwrite files of the same name in the destination without prompting. If this is a concern there is a forked version by user SuraAzure on github that appends a sequence number to the filename before moving if a file with the same name already exists in the destination directory.