← 返回文章列表

在automator里使用python3


title: 在automator里使用python3 author: Aynakeya tags:

categories:

  • Programming date: 2018-12-31 22:23:25

在automator里使用python3
使用/bin/bash,然后看下面代码。

export PATH+=:/usr/local/bin:/usr/bin:/bin
/usr/local/bin/python3 << "EOF" - "$@"
      //python codes
EOF

e.g. 实现FFmpeg提取音频。
export PATH+=:/usr/local/bin:/usr/bin:/bin
/usr/local/bin/python3 << "EOF" - "$@"
import sys,os
import subprocess

files = [] for f in sys.argv[1:]: files.append(f) for file in files: videoPath = file audioPath = os.path.splitext(file)[0]+".m4a" status = subprocess.call(["ffmpeg", "-y", "-i", videoPath, "-acodec", "copy", "-vn", audioPath], shell=False) if status == 0: pass else: pass EOF