自动将插入媒体的内容复制到文件夹

时间:2011-06-21 15:49:56

标签: macos file shell copy applescript

我有很多先前备份的数据刻录在CD / DVD上以复制回我的硬盘。 我正在寻找一种方法将插入媒体上的所有内容转储到某个文件夹(pref。由卷名创建),通过一些自动方式(pref。通过 applescript shell脚本)那会:

  • 按卷名转储创建文件夹
  • 转储文件夹
  • 中插入媒体的内容
  • 弹出媒体
  • 等待插入下一个媒体

我的问题在于所有这些磁盘都有随机卷标签(它不是完全随机的,但让我们随机使用以确保)。

由于我事先不知道卷标,并且在Mac上动态分配了每个挂载点(在/ Volumes中)和设备名称(在/ dev中),我在哪里开始查找刚刚插入的介质(假设在脚本的时间内不会插入任何其他设备或媒体。)

我一直在寻找相当长的一段时间,但我发现的大多数事情都与已知的音量标签有关。

任何想法都会非常感激!

提前致谢!

1 个答案:

答案 0 :(得分:2)

您可以使用drutil和diskutil的组合。 drutil可以为您提供设备路径,并使用该diskutil可以为您提供卷名称。困难的部分是解析结果以获得你想要的东西。

试试这个......

set diskName to cdDVDName()
if diskName is missing value then error "Could not get the name of the inserted disk"
diskName

on cdDVDName()
    set diskName to missing value
    try
        set theConst to "Volume Name: "
        set drutilStatus to do shell script "drutil status -drive internal | grep \"/dev/\""
        set theDrive to "/dev/" & item -1 of (words of drutilStatus)
        set diskutilInfo to do shell script "diskutil info " & theDrive & " | grep \"" & theConst & "\""

        set text item delimiters to theConst
        set a to text items of diskutilInfo
        set text item delimiters to ""
        set diskName to item -1 of a
        repeat while diskName begins with space
            set diskName to text 2 thru -1 of diskName
        end repeat
        repeat while diskName ends with space
            set diskName to text 1 thru -2 of diskName
        end repeat
    end try
    return diskName
end cdDVDName

此脚本将弹出cd / dvd ...

do shell script "drutil tray eject"
相关问题