Applescript 苹果脚本-选择文件,排除类型,压缩

Applescript 苹果脚本-选择文件,排除类型,压缩,applescript,Applescript,我需要压缩一个文件夹和数百个文件夹的所有子文件夹的内容。 是否可以运行一个命令,将特定文件夹提示符的所有文件(扩展名为.fla的所有文件除外)压缩到一个zipfile中 现在我正在复制文件夹,搜索所有的.fla文件,然后选择文件夹中的所有文件来压缩内容,而不是文件夹,然后创建一个压缩文件,这需要很长时间 我知道可以使用Apple脚本删除和复制文件。但是这在上面提到的顺序+压缩中也起作用吗?您的第一步应该是确定.fla是什么类型的文件。要执行此操作,请运行此脚本并选择一个.fla文件: tell

我需要压缩一个文件夹和数百个文件夹的所有子文件夹的内容。 是否可以运行一个命令,将特定文件夹提示符的所有文件(扩展名为.fla的所有文件除外)压缩到一个zipfile中

现在我正在复制文件夹,搜索所有的.fla文件,然后选择文件夹中的所有文件来压缩内容,而不是文件夹,然后创建一个压缩文件,这需要很长时间


我知道可以使用Apple脚本删除和复制文件。但是这在上面提到的顺序+压缩中也起作用吗?

您的第一步应该是确定.fla是什么类型的文件。要执行此操作,请运行此脚本并选择一个.fla文件:

tell application "Finder"
    set theFile to choose file
    display dialog (kind of theFile) as string
end tell
然后,要获取任何文件夹中除该类型以外的所有文件,可以运行此脚本,将纯文本替换为.fla的任何类型:

tell application "Finder"
    set thePath to choose folder
    set theFiles to get every file of folder thePath whose kind is not equal to "Plain Text"
end tell

从这里开始,这只是一个拉链的问题。在做了一些快速的谷歌搜索之后,看起来从applescript压缩的最简单的方法是使用do shell脚本,这应该不会太糟糕,因为您已经在一个漂亮的小数组中拥有了所有需要的文件。如果你想提高速度,我可能会建议把整个项目转移到bash上。这也将大大简化事情。祝你好运

好吧,所以我还是被这个问题困扰着。 我创建了一个Bash脚本,该脚本通过一个只有一行代码的Applescript可执行文件执行:

执行shell脚本/Volumes/Work/createZipFile.sh

Bash脚本打开Applescript,它让我提示一个我知道的文件夹,打开它就像运行一个运行为的Bash脚本一样愚蠢。然后使用该变量压缩此文件夹内容,而不压缩.fla文件


myFolder=`/usr/bin/osascript以防有人想使用我非常怀疑的脚本;,这是我的最终版本

#!/bin/bash
#Opens an applescript prompt window to select a folder
myFolder=`/usr/bin/osascript << EOT
    tell application "Finder"
        activate
        set myfolder to choose folder with prompt "Select the Folder that you want to Zip!"
    end tell
return (posix path of myfolder)
EOT`


# Terminate if the path is empty (canceled)
if [ -z "$myFolder" ];
then 
    #echo "Chose a folder!"
    exit 0
else
    #Change the directory to the above selected folder
    cd "$myFolder" 
    # Creates a ZipFile with todays date of the selected folder, neglecting the after -x listed filetypes
    zip  -r ZipFile_`eval date +%Y_%m_%d`.zip . -x "*.fla*" "*.AppleDouble*" "*.DS_Store*" 
    #echo "A zip File has been created"
fi

谢谢。我在过去使用了“名称扩展不是fla”,这似乎不起作用。文件扩展名作为字符串称为Adobe Flash Document。@user2607171将来如果遇到类似问题,请先查看AppleScript字典cmd-shft-L,它将为您提供几乎所有语法问题的答案。很可能是名称中带有空格的文件夹失败。Try:返回myFolder的posix路径的引号形式或更改cd$myFolder。到cd$myFolder
#!/bin/bash
#Opens an applescript prompt window to select a folder
myFolder=`/usr/bin/osascript << EOT
    tell application "Finder"
        activate
        set myfolder to choose folder with prompt "Select the Folder that you want to Zip!"
    end tell
return (posix path of myfolder)
EOT`


# Terminate if the path is empty (canceled)
if [ -z "$myFolder" ];
then 
    #echo "Chose a folder!"
    exit 0
else
    #Change the directory to the above selected folder
    cd "$myFolder" 
    # Creates a ZipFile with todays date of the selected folder, neglecting the after -x listed filetypes
    zip  -r ZipFile_`eval date +%Y_%m_%d`.zip . -x "*.fla*" "*.AppleDouble*" "*.DS_Store*" 
    #echo "A zip File has been created"
fi