简体   繁体   English

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

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

I've downloaded the following apple script, which moves airdropped files to a specified folder (which I'll refer to as the Airdrop folder):我下载了以下苹果脚本,它将空投文件移动到指定文件夹(我将其称为 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

I followed the instructions on this website to set it up as a folder actions script.我按照本网站上的说明将其设置为文件夹操作脚本。

However, if I move an airdropped file out of my newly created airdrop folder and back into my downloads folder, it gets automatically put BACK in the airdrop folder.但是,如果我将空投文件从新创建的空投文件夹中移回我的下载文件夹,它会自动放回空投文件夹中。 I don't want this to happen.我不希望这种情况发生。

I found that after applying this terminal command xattr -d com.apple.quarantine [file path of airdropped file] , the file will no longer get moved back into my airdrop folder after I move it out.我发现在应用此终端命令xattr -d com.apple.quarantine [file path of airdropped file] ,该文件在我移出后将不再移回我的空投文件夹。

MY question is: How do I integrate this command into the above apple script so that the airdropped files do not automatically get moved back to my airdrop folder after I move them out of it?我的问题是:如何将此命令集成到上述苹果脚本中,以便空投文件在我移出空投文件夹后不会自动移回我的空投文件夹?

One way to do this might be to set up another folder action script that removes the quarantine attribute from all files that are placed into my airdrop folder using the aforementioned terminal command.一种方法可能是设置另一个文件夹操作脚本,使用上述终端命令从放置在我的空投文件夹中的所有文件中删除隔离属性。

EDIT: HERE IS THE SOLUTION!!!编辑:这是解决方案!!! CREDIT: @Oantby信用:@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

So basically, you're just looking to get that line into the script?所以基本上,你只是想把那行写进脚本?

at the end, I'd probably add:最后,我可能会补充:

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

and then add clearQuarantineFlag(POSIX path of current_item) right before moveFile(current_item, alias AIRDROP_FOLDER) .然后添加clearQuarantineFlag(POSIX path of current_item)moveFile(current_item, alias AIRDROP_FOLDER)

Disclaimer: I wrote this based on what's there already, and haven't used much AppleScript in a while免责声明:我是根据已有的内容编写的,并且有一段时间没有使用太多 AppleScript

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

相关问题 如何使用在上述USB上运行的Apple脚本将文件复制到USB? - How do I Copy files to a USB with apple script that runs on said USB? 如何使用 Apple Script 退出多个版本的 Firefox? - How do I quit multiple versions of Firefox with Apple Script? 如何制作苹果脚本以将屏幕截图保存到剪贴板? - How do I make an apple script to save screenshots to clipboard? Apple Script - 将特定文件夹中的所有文件和/或文件夹标记为隐藏 - Apple Script - Mark all files and/or folders within a specific folder as hidden 如何创建.vimrc文件夹? - How do I create the folder .vimrc? 如何在 Cocoa 中创建一个新文件夹? - How do I create a new folder in Cocoa? 如何让苹果脚本告诉运行 python 脚本来运行 function? - How do I make apple script tell running python script to run a function? 使用Apple脚本压缩文件夹 - Zip a folder using apple script 我如何编写一个 bash 脚本来遍历文件夹中的每个目录并将所有 .txt 文件附加到一个文件中? - How do i write a bash script to loop through each directory in a folder and append all .txt files into a single file? 如何在保留文件夹结构的同时复制和替换Apple Automator中的文件? - How to copy and replace files in Apple Automator, while retaining folder structure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM