如果文件存在于带有AppleScript的其他配置文件中,您如何查找和复制文件?

时间:2013-05-19 21:18:24

标签: applescript duplicates repeat paragraphs

我正在尝试创建一个AppleScript来查看每个用户配置文件中的〜/ Library / Logs / DiagnosticReports中的崩溃日志。我最后使用*,因为可能有.crash .spin .hang文件,我需要将它们全部复制到当前桌面到“测试”文件夹但不确定这是否是正确的方法。

当我尝试运行它时,我得到了

  

错误“无法使”Test.txt“成为整数类型。”编号-1700来自   “Test.txt”为整数

try
    do shell script "ls /users >$HOME/Desktop/Users.txt"
    do shell script "mkdir ~/Desktop/Test"
end try

set b to boot volume of (system info)
set u to b & "Users"

set theFiles to paragraphs of "Test.txt"



repeat theFiles times
duplicate file u & theFiles & "~/Library/Logs/DiagnosticReports/Xxxxx*" to "~/Desktop/Test"

end repeat

感谢大家的帮助。

1 个答案:

答案 0 :(得分:1)

只需使用do shell脚本:

do shell script "mkdir -p ~/Desktop/Test
cp /Users/*/Library/Logs/DiagnosticReports/* ~/Desktop/Test" with administrator privileges

或循环浏览folders of (path to users folder)

tell application "Finder"
    if exists folder "Test" of desktop then
        set d to folder "Test" of desktop
    else
        set d to make new folder at desktop with properties {name:"Test"}
    end if
    repeat with f in (get folders of (path to users folder))
        tell contents of f
            if exists folder "DiagnosticReports" of folder "Logs" of folder "Library" then
                duplicate items of folder "DiagnosticReports" of folder "Logs" of folder "Library" to d
            end if
        end tell
    end repeat
end tell

如果您无权读取其他用户的文件,则可以使用launchctl unload /System/Library/LaunchAgents/com.apple.Finder.plist; sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder以root用户身份运行Finder。