Macos 自动将插入介质的内容复制到文件夹
我有很多以前备份的数据烧录在CD/DVD上,以便复制回硬盘。 我正在寻找一种方法,通过某种自动方式(首选通过applescript或shell脚本)将插入媒体上的所有内容转储到某个文件夹(首选通过卷名创建),该方法将:Macos 自动将插入介质的内容复制到文件夹,macos,file,shell,copy,applescript,Macos,File,Shell,Copy,Applescript,我有很多以前备份的数据烧录在CD/DVD上,以便复制回硬盘。 我正在寻找一种方法,通过某种自动方式(首选通过applescript或shell脚本)将插入媒体上的所有内容转储到某个文件夹(首选通过卷名创建),该方法将: 按卷名转储创建文件夹 将插入媒体的内容转储到文件夹中 弹出介质 等待插入下一个介质 我的问题在于所有这些磁盘都有随机的卷标签(这不是完全随机的,但让我们用随机来确定) 因为我事先不知道卷标,而且每个装入点(in/Volumes)和设备名(in/dev)都是在Mac上动态分配的
- 按卷名转储创建文件夹
- 将插入媒体的内容转储到文件夹中
- 弹出介质
- 等待插入下一个介质
提前谢谢 您可以使用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"
令人惊叹的!非常感谢:)通过这个脚本学到了一些东西。应可附加到/卷的文件夹操作。剩下的唯一一件事是,这个脚本向我展示了两张似乎没有卷标的光盘,虽然Finder向我展示了类似“020901415”的smth,但diskutil向我展示了磁盘实际上没有卷标。