0

我必须将文件复制到很多 U 盘。因此,我正在尝试给我写一个简短的小程序。我不熟悉applescript,所以如果有人能给我一些提示,那就太好了。

到目前为止我所拥有的:

10位USB-Hub

重命名棒的简短脚本。

现在我被困在将文件复制到每个连接的棒上:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups"}     

set myPath to ("Macintosh HD:Users:myusername:USB-Stick") as string
tell application "System Events"
set rootVolume to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolume
repeat with aVolume in allVolumes
    if aVolume is not in ignoredVolumes then
        set name of disk item (path of rootVolume & aVolume) to "Stickname"
    end if
end repeat
end tell

我现在需要做的是从 myPath 复制到每个连接的 USB-Stick。因为它们都具有相同的名称,所以它们将在名称后面安装数字(Stickname,Stickname 1,Stickname 2,...)

所以我需要在我的循环中将复制命令添加到刚刚重命名的棒中。

希望有人能帮帮我。

4

3 回答 3

1

使用 shell 脚本会更容易:

do shell script "cp -R ~/USB-Stick/ /Volumes/Stickname*"
于 2012-09-06T12:08:11.867 回答
1

你可以尝试这样的事情:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups", "iDisk", "net", "home"}
set myPath to (path to home folder as text) & "USB-Stick:"
tell application "System Events" to set theDisks to every disk
repeat with aDisk in theDisks
    if aDisk's name is not in ignoredVolumes then
        set diskPath to path of aDisk
        tell application "Finder" to duplicate myPath to diskPath with replacing
    end if
end repeat
于 2012-09-06T16:30:13.310 回答
0

谢谢你的提示。我现在用以下代码解决了它:

property ignoredVolumes : {"Macintosh HD", "Time Machine Backups"}   -- add as needed
property counter : 0
tell application "System Events"
set rootVolume to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolume
set StartTime to (get current date)
repeat with aVolume in allVolumes
    if aVolume is not in ignoredVolumes then
        set newName to "XXX" & counter as string
        log newName & " in Progress... "
        set name of disk item (path of rootVolume & aVolume) to newName
        set counter to counter + 1
        set scr to ("cp ~/USB-Stick/* /Volumes/" & newName)
        do shell script scr
        set name of disk item (path of rootVolume & newName) to "XXX"
        do shell script "diskutil unmount /Volumes/XXX"
        log newName & " finished."
    end if
end repeat
set endTime to (get current date)
set dur to (endTime - StartTime)
display dialog "Process took " & dur & "seconds."
end tell

希望这将有助于其他有同样问题的人。

只有一个外观问题:调用两个 shell 脚本会引发错误 -10004 但仍然有效。尝试告诉应用程序“Finder”或“终端”,但错误仍然存​​在并且已被其他错误添加,所以我坚持使用我的原始解决方案。

亲切的问候

于 2012-09-07T06:03:14.973 回答