首页 > 解决方案 > 带有变量的终端命令的自动化服务

问题描述

我是一名寻求自动化某些流程的艺术家。不幸的是,即使是这个看似基本的问题,我也离编码太远了。我在为这项任务寻求专业人士的帮助而哭泣:

我需要通过 Automator 创建一个服务,该服务将使用 FFMPEG 重新编码视频文件。它基本上应该做我在终端中执行时手动执行的操作,如下所示:

ffmpeg —i FILE_NAME.EXTENSION -vf "vflip,hflip" -an FILE_NAME_converted.MP4

当此脚本被包装到服务中时,FILE_NAME 必须替换为应用服务的文件。如何在 Shell-script 的 AppleScript 中使用这些变量?我将非常感谢任何建议甚至分步指导。谢谢!

标签: shellterminalapplescriptautomatorosx-services

解决方案


我能够弄清楚。这是适用于我的 AppleScript 代码:

on run {input, parameters}
    tell application "Finder"
        set theWin to window 1
        set thePath to (POSIX path of (target of theWin as alias))
        set theFile to name of file input
    end tell

    tell application "Terminal"
        activate
        set currentTab to do script ("cd " & thePath)
        do script ("ffmpeg -i " & theFile & " -vf \"vflip,hflip\" -an " & theFile & "_converted.mp4") in currentTab
        set frontWindow to window 1
        repeat until busy of frontWindow is false
            delay 1
        end repeat
        quit
    end tell
end run

推荐阅读