繁体   English   中英

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

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

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

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

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

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

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

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

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

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

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

最后,我可能会补充:

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)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM