如何创建一个苹果脚本来更改空投文件的目标文件夹?

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

我已经下载了以下苹果脚本,它将空投文件移动到指定文件夹(我将其称为空投文件夹):

property AIRDROP_FOLDER : "Macintosh HD:Users:pschorn:Airdrop"
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'"

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

我按照此 website 上的说明将其设置为文件夹操作脚本。

但是,如果我将空投文件从我新创建的空投文件夹中移回我的下载文件夹,它会自动放回空投文件夹中。我不会我不希望发生这种情况。

我发现在应用此终端命令后xattr -d com.apple.quarantine [file path of airdropped file],文件在我将其移出后将不再移回我的空投文件夹。

我的问题是:如何将此命令集成到上述 apple 脚本中,以便空投文件在我将其移出后不会自动移回我的空投文件夹?

执行此操作的一种方法可能是设置另一个文件夹操作脚本,该脚本使用上述终端命令从放置到我的空投文件夹中的所有文件中删除隔离属性。

编辑:这是解决方案!!! 来源:@Oantby

property AIRDROP_FOLDER : "Macintosh HD:Users:pschorn:Airdrop"
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'"

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
            clearQuarantineFlag(POSIX path of current_item)
            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 clearQuarantineFlag(file_path)
    do shell script "xattr -d com.apple.quarantine '" & file_path & "'"
end clearQuarantineFlag

所以基本上,您只是想将该行添加到脚本中?

最后,我可能会补充:

on clearQuarantineFlag(file_path)
    do shell script "xattr -d com.apple.quarantine '" & file_path & "'"
end clearQuarantineFlag

然后在moveFile(current_item, alias AIRDROP_FOLDER)前加上clearQuarantineFlag(POSIX path of current_item).

免责声明:我根据已有的内容编写了这篇文章,并且有一段时间没有使用太多 AppleScript