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

问题描述 投票:0回答:1

我是一位寻求自动化某些流程的艺术家。不幸的是,即使是这个看似基本的问题,我也无法编码。我在此任务上需要专业人士的帮助:

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

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

当将此脚本包装到服务FILE_NAME中时,必须用应用该服务的文件替换。如何在Shell-script的AppleScript中使用此类变量?我将不胜感激任何建议,甚至分步说明。谢谢!

shell terminal applescript automator osx-services
1个回答
0
投票

是的!我做到了

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
© www.soinside.com 2019 - 2024. All rights reserved.