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

发布于 2024-11-16 06:45:25 字数 456 浏览 0 评论 0原文

我有很多以前备份的数据刻录在 CD/DVD 上,可以复制回我的硬盘。 我正在寻找一种方法,通过某种自动化方式(首选通过 applescriptshell 脚本),这将:

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

我的问题在于,所有这些磁盘都有随机卷标(它不是完全随机的,而是为了确定起见,我们随机进行)。

由于我事先不知道卷标,并且每个挂载点(在 /Volumes 中)和设备名称(在 /dev 中)都是在 Mac 上动态分配的,所以我从哪里开始找到刚刚插入的媒体(假设没有)其他设备或媒体将在脚本执行期间插入)。

我已经寻找了很长一段时间,但我发现的大多数内容都涉及已知的卷标签。

任何想法将不胜感激!

提前致谢!

I have a lot of previously backed up data burned on CDs/DVDs to copy back to my hard drive.
I'm looking for a way to dump everything on an inserted media to some folder (pref. created by volume name), by some automated way (pref. via applescript or shell script) that would:

  • create folder by volume name dump
  • dump contents of inserted media in folder
  • eject media
  • wait for next media to be inserted

My problem resides in the fact the all of these disks have random volume labels (it's not exactly random, but let's go with random to be sure).

Since I don't know the volume label beforehand, and every mount point (in /Volumes) and device name (in /dev) is dynamically assigned on Mac, where do I start to find what media has just been inserted (assuming to no other devices or media are going to be inserted for the time of the script).

I've been looking for quite some time, but most things I found deal with known volume labels.

Any ideas would be very appreciated!

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2024-11-23 06:45:25

您可以结合使用 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"

You can use a combination of drutil and diskutil. drutil can give you the device path and using that diskutil can give you the volume name. The tough part is parsing the results to get what you want.

Try this...

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

This script will eject the cd/dvd...

do shell script "drutil tray eject"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文