删除多个文件 - 仅接收一个身份验证提示

时间:2015-09-11 22:07:50

标签: file applescript directory delete-file

我尝试创建一个脚本来删除同一文件夹中的多个文件,而无需进行两次身份验证。我已经尝试了很多东西,但我对AppleScript来说是一个超级新手,我一直在努力。非常感谢任何帮助。

set colorProfiles to (POSIX file "/Library/ColorSync/Profiles")
set coatedToDelete to "Pantone+ Solid Coated.csv"
set uncoatedToDelete to "Pantone+ Solid Uncoated.csv"

try
    --Notification window with info
    display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note

    --Deletes both Pantone+ .csv files
    tell application "Finder"
        delete file (coatedToDelete of folder colorProfiles)
        delete file (uncoatedToDelete of folder colorProfiles)

    end tell
    --Successful deletion notification
    display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note


on error
    --Error message notification
    display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try

1 个答案:

答案 0 :(得分:0)

使用shell命令rm,它可以通过一次身份验证删除一行中的多个文件。与Finder的不同之处在于文件会立即删除,而不是移动到垃圾文件夹。

set colorProfiles to "/Library/ColorSync/Profiles/"
set coatedToDelete to colorProfiles & "Pantone+ Solid Coated.csv"
set uncoatedToDelete to colorProfiles & "Pantone+ Solid Uncoated.csv"

try
  --Notification window with info
  display dialog ("This script will automagically delete your outdated Pantone color books. Please make sure an admin is nearby to authenticate (twice) if prompted.") with icon note

  --Deletes both Pantone+ .csv files
  do shell script "/bin/rm " & quoted form of coatedToDelete & space & quoted form of uncoatedToDelete with administrator privileges

  --Successful deletion notification
  display dialog ("The outdated color book deletion was successful!") buttons {"Great!"} with icon note


on error
  --Error message notification
  display dialog ("This script was unable to delete your legacy Pantone color books.") buttons {"OK"} with icon caution
end try