问题描述
限时送ChatGPT账号..脚本如下:
tell application "Finder"
set destinFolder to (choose folder)
try
move selection to destinFolder
on error vMessage number -15267
display dialog "" & vMessage
end try
end tell
基本上,如果目标文件夹中已经存在同名文件,我希望用户可以选择复制、替换或跳过该文件并继续下一个文件移动使用 AppleScript.就像下图一样.
Basically,if a file with the same name has already existed in the destination folder, I want users have the choice to duplicate,replace or just skip that file and continue the next file movement using AppleScript. Just like the pic below.
更新:我知道如何显示像上面那样的对话框,问题是我不知道如何在 AppleScript 中实现复制、替换或跳过"逻辑.此外,我想保留这一行:
Update: I know how to display a dialog like the one above,the problem is I don't know how to implement the "duplicate,replace or just skip" logic in AppleScript. And besides, I want to keep this line:
move selection to destinFolder
因为这行代码在单个对话框中显示了适当的移动进度百分比,使用 repeat
将失去这种好处.
Because this line of code show a proper moving progress percentage in a single dialog, using repeat
will lose that benefit.
推荐答案
你可以试试这样的:
set destinFolder to (choose folder)
set destItems to every paragraph of (do shell script "ls " & quoted form of (POSIX path of destinFolder))
tell application "Finder"
set mySelection to selection
repeat with anItem in mySelection
set itemName to anItem's name
if itemName is in destItems then
display alert "An item named " & itemName & " already exists in this location. Do you want to replace it with the one you're moving?" buttons {"Skip", "Replace"} default button "Replace"
if button returned of the result = "Replace" then move anItem to destinFolder with replacing
else
try
move anItem to destinFolder
end try
end if
end repeat
end tell
或者这个:
set destinFolder to (choose folder)
tell application "Finder"
set mySelection to selection
repeat with anItem in mySelection
try
move anItem to destinFolder
on error errMsg number errNum
if errNum = -15267 then
display alert "An item named " & itemName & " already exists in this location. Do you want to replace it with the one you're moving?" buttons {"Skip", "Replace"} default button "Replace"
if button returned of the result = "Replace" then move anItem to destinFolder with replacing
else
tell me
activate
display alert errMsg & return & return & "Error number" & errNum buttons "Cancel"
end tell
end if
end try
end repeat
end tell
编辑此脚本不会让您选择目标文件夹中存在的每个项目
EDIT This script will not give you a choice for each item that exists in the destination folder
set destinFolder to (choose folder)
tell application "Finder"
set mySelection to selection
try
move mySelection to destinFolder
on error errMsg number errNum
if errNum = -15267 then
display alert "One or more items already exist in this location. Do you want to replace them with the ones you're moving?" buttons {"Skip", "Replace"} default button "Replace"
if button returned of the result = "Replace" then move mySelection to destinFolder with replacing
else
tell me
activate
display alert errMsg & return & return & "Error number" & errNum buttons "Cancel"
end tell
end if
end try
end tell
这篇关于我试图告诉 Finder 使用 AppleScript 移动文件.但我不知道如何处理重复/替换/跳过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论