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

时间:2016-04-07 08:06:55

标签: macos applescript automator

我是Automator的新手 对于简单的操作,有许多examples 但是我找不到示例或documentation在安装特定磁盘后启动某些应用程序 它在工作中非常有用 有人这样做了吗?

2 个答案:

答案 0 :(得分:1)

好的,你想要Automator方式,你得到它:-D

  1. 创建文件夹操作
  2. 类型的新Automator操作
  3. 选择系统的音量文件夹作为输入,我认为您必须使用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
    
  6. 诀窍是观察系统默认挂载点(/Volumes)内的更改。每次向文件夹添加某些内容时,AppleScript都将被执行,新添加的项目(也称为新卷)的别名将位于给予脚本的input参数内。 我们遍历所有项别名的列表并获取别名的真实名称,将其与我们的触发器名称进行比较,如果匹配,我们将启动应用程序。

    与Automator,Michael / Hamburg一起玩得很开心

答案 1 :(得分:0)

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

  1. 创建类型为文件夹动作
  2. 的新的Automator动作 通过单击 Choose folder 下拉列表中的 Other ... ,并按 Cmd,选择
  3. 输入系统的 Volumes 文件夹作为输入。 + 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. 向工作流中添加其他操作,例如要求确认复制查找器项启动应用程序
相关问题