我需要重命名并填充大约70个U盘。当它们被插入时,让Applescript自动运行会让事情变得简单得多。
发布于 2012-05-11 23:42:42
连接到OS X计算机的任何外部驱动器都会挂载到/Volumes
中。如果您查看该文件夹是否有更改,则可以选择添加的外部驱动器并对其进行处理。运行以下代码:
property ignoredVolumes : {"Macintosh HD", "Time Machine Backups"} -- add as needed
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 newName
end if
end repeat
end tell
将不在ignoredVolumes
列表中的驱动器重命名为newName
(拔掉除要忽略的驱动器之外的所有驱动器,在终端中运行ls /Volumes
并将名称添加到属性中)。要在每次更改时触发它,请将代码修改为Stay-Open script application
property pollIntervall : 60 -- in seconds
property ignoredVolumes : {…} -- from above
on run
my checkVolumes()
end run
on idle
my checkVolumes()
return pollInterval
end idle
on checkVolumes()
tell … end tell -- from above
end checkVolumes
并将其保存在AppleScript编辑器中(选择“AppleScript应用程序”,确保在执行此操作时勾选了“保持打开”)。一旦启动,该脚本将继续运行,每隔pollInterval
秒执行一次on idle
处理程序。
如果您基本上是在执行一次批处理作业,这将会做得很好。如果您想要一个更持久的解决方案,而不依赖于运行持续打开的脚本应用程序,您可以
/Volumes
文件夹(这是对Philip Regan on 的提示;有关如何在this Mac OS X Hints post中配置操作的详细信息)-优势在于您可以严格处理对/Volumes
的添加,或者通过创建一个将D18键设置为true
的LaunchAgent来使用launchd
-该脚本/应用程序将在每次装载文件系统时触发代理启动的脚本/应用程序(对C20的提示;有关详细信息,请参阅Apple’s Technical Note TN2083 )。H222F223https://stackoverflow.com/questions/10553225
复制相似问题