2013-05-19 29 views
0

我想創建一個applescript來查看每個用戶配置文件中的崩潰日誌〜/ Library/Logs/DiagnosticReports ..我使用*在最後,因爲可能有.crash .spin .hang文件,我需要將它們全部複製到當前桌面到「測試」文件夾中,但我不確定這是否是正確的方式。如何查找和複製文件(如果它們存在於具有applescript的其他配置文件中)?

當我嘗試運行它,我得到

錯誤「無法讓\」 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 

感謝所有幫助。

回答

1

只要用做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

+0

嗨,謝謝,但這兩個腳本似乎只從當前用戶獲取日誌,我把一個崩潰日誌的另一個用戶進行測試,它沒有複製它。 – Breathable

+0

如果您需要root權限,請以root用戶身份添加'擁有管理員權限'或運行Finder。 – user495470

+0

對不起,但你會如何設置呢? – Breathable

相關問題