我是Automator的新手 对于简单的操作,有许多examples 但是我找不到示例或documentation在安装特定磁盘后启动某些应用程序 它在工作中非常有用 有人这样做了吗?
答案 0 :(得分:1)
好的,你想要Automator方式,你得到它:-D
Go to folder
并输入/Volumes
使用以下脚本并定义前两个变量以满足您的需求:
on run {input, parameters}
-- define the volume name and the application to start
set triggeringVolumeName to "YOUR_VOLUME_NAME"
set applicationToStart to application "Microsoft Word"
-- walk through all newly mounted volumes
repeat with aMountedVolumeAlias in input
-- get the volume name from the given alias
tell application "System Events" to set mountedVolumeName to name of aMountedVolumeAlias
-- compare the volume name with the defined trigger name
if mountedVolumeName is triggeringVolumeName then
-- launch the target application
launch applicationToStart
-- all is done stop checking
exit repeat
end if
end repeat
return input
end run
诀窍是观察系统默认挂载点(/Volumes
)内的更改。每次向文件夹添加某些内容时,AppleScript都将被执行,新添加的项目(也称为新卷)的别名将位于给予脚本的input
参数内。
我们遍历所有项别名的列表并获取别名的真实名称,将其与我们的触发器名称进行比较,如果匹配,我们将启动应用程序。
与Automator,Michael / Hamburg一起玩得很开心
答案 1 :(得分:0)
详细说明ShooTerKo的答案,我编写了以下脚本,如果找到triggeringVolumeName,它将继续工作流。这样,可以将实际启动(或任何其他工作流程操作)移到Applescript之外:
/Volumes
使用以下脚本并更改YOUR_VOLUME_NAME
以满足您的需求:
on run {input, parameters}
-- define the volume name and the application to start
set triggeringVolumeName to "YOUR_VOLUME_NAME"
-- walk through all newly mounted volumes
repeat with aMountedVolumeAlias in input
-- get the volume name from the given alias
tell application "System Events" to set mountedVolumeName to name of aMountedVolumeAlias
-- compare the volume name with the defined trigger name
if mountedVolumeName is triggeringVolumeName then
-- continue workflow
return input
end if
end repeat
-- if repeat finished without match, cancel workflow
error number -128
end run