我需要重命名并填充大约70个USB记忆棒.如果Applescript在插入时自动运行会使其更加简单.
连接到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
Run Code Online (Sandbox Code Playgroud)
将重命名不在ignoredVolumes列表中的驱动器(拔掉除了您要忽略的驱动器,ls /Volumes在终端中运行并将名称添加到属性中)newName.要在每次更改时触发此操作,请将代码修改为Stay-Open脚本应用程序:
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
Run Code Online (Sandbox Code Playgroud)
并将其保存在AppleScript编辑器中(选择"AppleScript应用程序",确保勾选"保持打开状态").一旦启动,脚本将继续运行,on idle每秒执行一次处理程序pollInterval.
如果您基本上只进行一次一次批处理作业,这将很好.如果您想要一个不依赖于运行保持打开的脚本应用程序的更永久的解决方案,您也可以
/Volumes文件夹(在Ask Different上向 Philip Regan提示;有关如何在此Mac OS X Hints帖子中配置操作的详细信息) - 优点是您严格处理添加/Volumes,或者launchd通过创建具有一个LaunchAgent StartOnMount键设置为true-将触发脚本/应用程序代理启动每一个文件系统安装(帽子,以尖端时间的丹尼尔·贝克提出不同的 ;看到苹果公司的技术说明TN2083的血淋淋的细节).| 归档时间: |
|
| 查看次数: |
4596 次 |
| 最近记录: |