简体   繁体   English

带有变量的终端命令的自动化服务

[英]Automator Service for Terminal commands with variables

I'm an artist looking for automating some processes.我是一名寻求自动化某些流程的艺术家。 Unfortunately, I'm too far from coding to wrap my head around even this seemingly elementary problem.不幸的是,即使是这个看似基本的问题,我也离编码太远了。 I'm crying for professional's help with this task:我在为这项任务寻求专业人士的帮助而哭泣:

I need to create a service via Automator that will re-encode video files with FFMPEG.我需要通过 Automator 创建一个服务,该服务将使用 FFMPEG 重新编码视频文件。 It should basically do what I'm doing manually when executу in Terminal a line like this:它基本上应该做我在终端中执行时手动执行的操作,如下所示:

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

When this script is wrapped into the service FILE_NAME must be substituted with the file the service is applied to.当此脚本被包装到服务中时,FILE_NAME 必须替换为应用服务的文件。 How can I use such variables in AppleScript of Shell-script?如何在 Shell 脚本的 AppleScript 中使用这些变量? I would highly appreciate any advice or even step-by-step instruction.我将非常感谢任何建议甚至分步指导。 Thank you!谢谢!

I was able to figure it out.我能够弄清楚。 Here is the AppleScript code that works for me:这是适用于我的 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM