如何在使用 Automator 安装特定光盘后启动应用程序

How to launch an application after a specific Disc was mounted using Automator

我是 Automator 的新手。
简单的动作有很多examples
但是我找不到示例或 documentation 在安装特定磁盘后启动某些应用程序。
对工作会有很大帮助。
有人做过吗?

好的,你想要 Automator 方式,你明白了 :-D

  1. 创建类型为 文件夹操作
  2. 的新 Automator 操作
  3. 选择系统的 Volumes 文件夹作为输入,我认为您必须使用 Go to folder 并键入 /Volumes
  4. 第一步选择执行Applescript
  5. 使用以下脚本并定义前两个变量以满足您的需要:

    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

详细说明 ShooTerKo 的回答 我已经编写了以下脚本,如果找到 triggeringVolumeName,它会继续工作流。这样就可以将实际启动(或任何其他工作流程操作)移到 Applescript 之外:

  1. 创建类型为 文件夹操作
  2. 的新 Automator 操作
  3. 通过单击选择文件夹[中的其他...,选择系统的Volumes文件夹作为输入。 =32=] 下拉菜单,按 Cmd+Shift+G 并输入 /Volumes
  4. 第一步选择执行Applescript
  5. 使用以下脚本并更改 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
    
  6. 向工作流添加其他操作,例如请求确认复制 Finder 项目启动应用程序