【问题标题】:How do I create an apple script that changes the destination folder of airdropped files?如何创建一个更改空投文件目标文件夹的苹果脚本?
【发布时间】:2020-03-23 14:50:55
【问题描述】:

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

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 上的说明将其设置为文件夹操作脚本。

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

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

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

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

编辑:这是解决方案!!! 来源:@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

【问题讨论】:

    标签: macos terminal applescript finder


    【解决方案1】:

    所以基本上,你只是想把那一行写进脚本?

    最后,我可能会补充:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多