Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Question:

Question: Running Python in Automator

I am trying to make a pic to text code for Python. I run it in Atom(compiler) and it works fine. I run it in Terminal and it runs fine, but I'm trying to do it in automator but it isn't working. Here's the error:


User uploaded file

macOS High Sierra (10.13.2)

Posted on

Reply

Page content loaded

Mar 11, 2018 11:35 AM in response to mmodi1 In response to mmodi1

Because it is using the default system PATH, and not yours, so it cannot find the Python program. My .bash_profile has a custom PATH statement in it that also includes my $HOME directory, and current (.) directory. You may have to still use ./PicToText.py to force it to look in the Documents folder for that script — or its full path.


Also, if your Python program is written to get ARGV elements passed in from the previous action, then change the pass input to Arguments. If you are using the Python fileinput module to slurp standard input, then leave the current setting to stdin.


(cd ~/Documents; source ~/.bash_profile; python -d -c PicToText.py) > ~/Desktop/PicToText.log

Mar 11, 2018 11:35 AM

Reply Helpful

Mar 11, 2018 11:43 AM in response to VikingOSX In response to VikingOSX

Ok so I'm having the screenshot save the picture file in Documents(where my PicToText.py is) and then as soon as that's done I want to have the Python Code to run. (So do I use arguments or stdin). Sorry I am so new to this I've had Mac for a few days but want to get this working. So then after I change that setting what will I enter into the ShellScript? Here is my code:


User uploaded file

Mar 11, 2018 11:43 AM

Reply Helpful

Mar 11, 2018 11:49 AM in response to mmodi1 In response to mmodi1

As your code is written, it is using neither ARGV (command-line arguments), or standard input, so the Python script will simply ignore any pass input action setting.


Are you getting text from your image in helloworld.txt when the application runs?

Mar 11, 2018 11:49 AM

Reply Helpful

Mar 11, 2018 12:16 PM in response to mmodi1 In response to mmodi1

In the Run Shell Script action, set the Shell selection to /usr/bin/python.


Python does not implicitly know that your PicToText.py script is in your Documents folder, so you must tell it with (the following is all one line and may wrap):


(cd ~/Documents;source ~/.bash_profile;python -d -c ./PicToText.py) > ~/Desktop/PicToText.log

Mar 11, 2018 12:16 PM

Reply Helpful

Mar 11, 2018 1:25 PM in response to mmodi1 In response to mmodi1

Do not use any ~ in your scripts. Your not running were you think.


Use all explicit paths. Of course, this is a make it work approach. run the id command to see what is going on.


I suggest you first debug this in an actual applescript. It could be that any time a shell command get an error your applescript quits. I think so. See my applescript in the next post for catching errors.


R

Mar 11, 2018 1:25 PM

Reply Helpful

Mar 11, 2018 1:23 PM in response to rccharles In response to rccharles

An Applescript to show user info.


(*

It is easier to diagnose problems with debug information. I suggest adding
log statements to your script to see what is going on.  Here is an example.


    Author: rccharles

    For testing, run in the Script Editor.
      1) Click on the Event Log tab to see the output from the log
          statement
      2) Click on Run
   
  For running shell commands see:
  http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html



*)


on run
    -- Write a message into the event log.
    log "  --- Starting on " & ((current date) as string) & " --- "
    --  debug lines
    set desktopPath to (path to desktop) as string
    log "desktopPath = " & desktopPath

    set unixDesktopPath to POSIX path of desktopPath
    log "unixDesktopPath = " & unixDesktopPath

Here is an applescript to display some system info.
    set quotedUnixDesktopPath to quoted form of unixDesktopPath
    log "quoted form is " & quotedUnixDesktopPath

    try
        set fromUnix to do shell script "pwd  "
        display dialog "pwd " & return & fromUnix giving up after 7
        set fromUnix to do shell script "id "
        display dialog "id " & return & fromUnix giving up after 7
     
     
        set fromUnix to do shell script "ls -l  " & quotedUnixDesktopPath
        display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix giving up after 10
    on error errMsg
        log "ls -l error..." & errMsg
    end try

end run




User uploaded file


User uploaded file


Third display not recorded.

Mar 11, 2018 1:23 PM

Reply Helpful
User profile for user: mmodi1

Question: Running Python in Automator