0

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

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

错误“无法将 \"Test.txt\" 转换为整数类型。” 从“Test.txt”到整数的数字 -1700

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

感谢大家的帮助。

4

1 回答 1

0

只需使用 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.

于 2013-05-20T05:21:45.267 回答