使用 Applescript 将图像文件夹复制到另一个文件夹时遇到问题
Trouble copying folders of images to another folder with Applescript
我收到有关无法为整数创建别名的错误?不确定...
我正在尝试让这个片段获取一些文件夹(每个文件夹中都有一堆图像)并将内容复制到存档驱动器。
on open droppedItems
set user to do shell script "whoami"
set archivePath to "/Users/" & user & "/Desktop/Archive' 'Drive"
#tell application "Finder" to set jobName to name of item droppedItems
#I need to figure this out as it's not working the way I originally had it
tell application "Finder"
do shell script "mkdir -p " & archivePath & "/" & jobName & "RAW' 'FILES"
set localDestination to archivePath & "/" & jobName & "RAW' 'FILES"
do shell script "open " & localDestination
activate
set position of window 1 to {1000, 0}
end tell
**#this is where I'm having issues (obviously)**
repeat with i from 1 to count of droppedItems
set currentItem to item i of droppedItems
#display dialog (currentItem)
duplicate currentItem to localDestination #I've tried a few different things here...
end repeat
end open
代码中有很多问题。
最重要的是
droppedItems
是一个 list 项目。要获得名称,您必须使用一项。
- Finder 仅接受 HFS 路径(以冒号分隔),您甚至试图将文件复制为文字字符串。使用 HFS 路径,您无需转义 space 字符。在
do shell script
行中,路径用 quoted form of
. 转义
duplicate
命令属于Finder。它必须包裹在 tell application "Finder"
块中。
Finder window 无关紧要。您可以在不打开 window 的情况下复制项目。但是我添加了一行来打开文件夹。而且你也不需要重复循环。
on open droppedItems
set archivePath to (path to desktop as text) & "Archive Drive"
tell application "Finder" to set jobName to name of first item of droppedItems
set localDestination to archivePath & ":" & jobName & "RAW FILES"
do shell script "mkdir -p " & quoted form of POSIX path of localDestination
tell application "Finder"
duplicate droppedItems to folder localDestination
open folder localDestination
end tell
end open
如果您只想复制文件夹的内容,您确实需要一个重复循环
on open droppedItems
set archivePath to (path to desktop as text) & "Archive Drive"
tell application "Finder" to set jobName to name of first item of droppedItems
set localDestination to archivePath & ":" & jobName & "RAW FILES"
do shell script "mkdir -p " & quoted form of POSIX path of localDestination
tell application "Finder"
repeat with anItem in droppedItems
if class of anItem is folder then
duplicate every item of anItem to folder localDestination
else
duplicate anItem to folder localDestination
end if
end repeat
open folder localDestination
end tell
end open
我收到有关无法为整数创建别名的错误?不确定...
我正在尝试让这个片段获取一些文件夹(每个文件夹中都有一堆图像)并将内容复制到存档驱动器。
on open droppedItems
set user to do shell script "whoami"
set archivePath to "/Users/" & user & "/Desktop/Archive' 'Drive"
#tell application "Finder" to set jobName to name of item droppedItems
#I need to figure this out as it's not working the way I originally had it
tell application "Finder"
do shell script "mkdir -p " & archivePath & "/" & jobName & "RAW' 'FILES"
set localDestination to archivePath & "/" & jobName & "RAW' 'FILES"
do shell script "open " & localDestination
activate
set position of window 1 to {1000, 0}
end tell
**#this is where I'm having issues (obviously)**
repeat with i from 1 to count of droppedItems
set currentItem to item i of droppedItems
#display dialog (currentItem)
duplicate currentItem to localDestination #I've tried a few different things here...
end repeat
end open
代码中有很多问题。
最重要的是
droppedItems
是一个 list 项目。要获得名称,您必须使用一项。- Finder 仅接受 HFS 路径(以冒号分隔),您甚至试图将文件复制为文字字符串。使用 HFS 路径,您无需转义 space 字符。在
do shell script
行中,路径用quoted form of
. 转义
duplicate
命令属于Finder。它必须包裹在tell application "Finder"
块中。
Finder window 无关紧要。您可以在不打开 window 的情况下复制项目。但是我添加了一行来打开文件夹。而且你也不需要重复循环。
on open droppedItems
set archivePath to (path to desktop as text) & "Archive Drive"
tell application "Finder" to set jobName to name of first item of droppedItems
set localDestination to archivePath & ":" & jobName & "RAW FILES"
do shell script "mkdir -p " & quoted form of POSIX path of localDestination
tell application "Finder"
duplicate droppedItems to folder localDestination
open folder localDestination
end tell
end open
如果您只想复制文件夹的内容,您确实需要一个重复循环
on open droppedItems
set archivePath to (path to desktop as text) & "Archive Drive"
tell application "Finder" to set jobName to name of first item of droppedItems
set localDestination to archivePath & ":" & jobName & "RAW FILES"
do shell script "mkdir -p " & quoted form of POSIX path of localDestination
tell application "Finder"
repeat with anItem in droppedItems
if class of anItem is folder then
duplicate every item of anItem to folder localDestination
else
duplicate anItem to folder localDestination
end if
end repeat
open folder localDestination
end tell
end open