Applescript 速度极慢 Finder.app 设置评论

Applescript 速度极慢 Finder.app 设置评论

这是脚本:

set d to do shell script "date +%d-%m-%Y"
tell application "Finder"
    set dir to POSIX file ("/Volumes/Xsan/PathTo/Folder") as alias
    repeat with f in entire contents of dir
        if comment of f does not start with "Archived" then
            set comment of f to "Archived " & d
            set label index of f to 2
        end if
    end repeat
end tell

我的问题是,我正在对一个包含 1000 张图片和文件夹的文件夹运行此程序。Finder 的 CPU 使用率达到 90% 左右,并且每个文件/文件夹大约需要 40 秒来设置注释和标签。

有没有人能建议一些优化方法?或者,修改代码,让这个任务 100% 用 Bash 脚本实现?(如果这有助于提高速度的话)。

我觉得“全部内容”命令中可能有一些东西把事情搞乱了。

就像在对给定文件或文件夹进行更改之前一样,在进行一次更改后,它会再次检查所有文件上的“已存档”标签。我以为这会在开始时缓存在内存中。

非常乐意听到您的任何想法!

干杯,

詹姆士

编辑:系统是 Snow Leopard Server 10.6.8,Xserve2,1

答案1

尝试这个:

    set time1 to do shell script "perl -e 'use Time::HiRes qw(time); print time'"

set d to do shell script "date +%d-%m-%Y"    
    tell application "Finder"
        set dir to POSIX file "/Volumes/Xsan/PathTo/Folder" as alias
        set eContents to entire contents of dir
        repeat with f in my eContents
            if comment of f does not start with "Archived" then
                set comment of f to "Archived " & d
                set label index of f to 2
            end if
        end repeat
    end tell

    set time2 to do shell script "perl -e 'use Time::HiRes qw(time); print time'"
    set millisec to (round ((time2 - time1) * 1000))

或者

set time1 to do shell script "perl -e 'use Time::HiRes qw(time); print time'"

set d to do shell script "date +%d-%m-%Y"
tell application "Finder"
    set dir to POSIX file "/Volumes/Xsan/PathTo/Folder" as alias
    set eContents to every file of (entire contents of dir) whose comment does not start with "Archived"
    repeat with f in my eContents
        set comment of f to "Archived " & d
        set label index of f to 2
    end repeat
end tell

set time2 to do shell script "perl -e 'use Time::HiRes qw(time); print time'"
set millisec to (round ((time2 - time1) * 1000))

相关内容