Hello
For your original python code, you may simply try the following automator workflow of single run shell script action. Note that there should not be used -c option in python invocation in this case.
1) Run Shell Script action
shell = /bin/bash
pass input = arguments or stdin (not relevant)
code = as follows:
#!/bin/bash
source ~/.bash_profile
cd ~/Documents || exit
python -d PicToText.py
---
For a little more general code processing arguments, you might try something like the following as python script:
#!/usr/bin/python
# coding: utf-8
#
# file:
# PicToText.py
#
# function:
# OCR image to text
#
# usage
# PicToText.py file [file ...]
#
# output file is named after input file's basename without extension followed by '.txt'
# e.g., file.png is OCR'ed and resulting text is saved in file.txt in the same directory as input
#
import sys, os
import pytesseract
from PIL import Image
for f in [ a.decode('utf-8') for a in sys.argv[1:] ]:
t = pytesseract.image_to_string(Image.open(f))
g, e = os.path.splitext(f)
with open(g + '.txt', 'w') as f1:
f1.write(t.encode('utf-8'))
And the following workflow of two acitons:
1) Run AppleScript action
code = as follows:
choose file with multiple selections allowed
2) Run Shell Script action
shell = /bin/bash
pass input = arguments
code = as follows:
#!/bin/bash
source ~/.bash_profile
cd ~/Documents || exit
python -d PicToText.py "$@"
Good luck,
H