我有一个问题,如果需要,我需要它提示输入管理员凭据并且找不到可行的解决方案。
set foo to computer name of (system info)
set p to (path to desktop)
set targetFile to "Macintosh HD:private:var:log:system.log:"
set targetPath to p & "LOGS-I-NEED-" & foo as text
try
if ("80" is not in (do shell script "id -G")) then
tell application "Finder" to duplicate file targetFile to targetPath
else
tell application "Finder" to duplicate file targetFile to targetPath
end if
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message & return & "targetFile:" & targetFile & return & return & "targetPath:" & targetPath buttons {"OK"} default button 1
end try
我也试过这个,但不知道如何 cp 到一个名称中有变量的文件夹。
try
set foo to computer name of (system info)
do shell script "sudo cp /Private/var/log/system.log ~/Desktop/{name:LOGS-I-NEED} & foo" with administrator privileges
end try
无论哪种方式都对我有用。
多谢你们!