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

时间:2019-11-28 01:20:41

标签: macos terminal applescript finder

我下载了以下苹果脚本,该脚本将空投的文件移动到指定的文件夹(我将其称为“空投”文件夹):

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=$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

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

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

我发现应用此终端命令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=$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
            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

1 个答案:

答案 0 :(得分:1)

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

最后,我可能会添加:

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

,然后在clearQuarantineFlag(POSIX path of current_item)之前添加moveFile(current_item, alias AIRDROP_FOLDER) right

免责声明:我是根据已经存在的内容编写此代码的,并且有一段时间没有使用太多AppleScript了