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

File 删除多个文件-仅接收一个身份验证提示,file,applescript,directory,delete-file,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

我正在尝试创建一个脚本来删除同一文件夹中的多个文件,而无需进行两次身份验证。我尝试过很多东西,但我对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

使用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

使用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

谢谢你的提醒。所以,在shell脚本之外和Applescript内部绝对没有办法做到这一点?另外,如果脚本/支持文件是分布式的,而您事先不知道CD的位置,那么您知道如何从applescript调用shell脚本吗?确实没有办法。什么是CD?我最终使用了你建议的bash脚本。抱歉,CD引用了更改目录。在bash和applescript中,无论脚本位于何处,导航到脚本的父文件夹都是我的一个难点。感谢大家的提醒。所以,在shell脚本之外和Applescript内部绝对没有办法做到这一点?另外,如果脚本/支持文件是分布式的,而您事先不知道CD的位置,那么您知道如何从applescript调用shell脚本吗?确实没有办法。什么是CD?我最终使用了你建议的bash脚本。抱歉,CD引用了更改目录。在bash和applescript中,导航到脚本的父文件夹(无论它位于何处)一直是我的一个难点。