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))

相關內容