Running Python in Automator
macOS High Sierra (10.13.2)
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
Good to see you contributing again.
V
I don't understand the apple script part and they Python code isn't making sense.
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 runThird display not recorded.
I get the same error when I run this script in Yosemite and High Sierra.
(*
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
set fromUnix to do shell script "pwd "
log "pwd " & return & fromUnix
set fromUnix to do shell script "id "
log "id " & return & fromUnix
set fromUnix to do shell script "python -V"
log "python " & return & fromUnix
set fromUnix to do shell script " /bin/ls -l /"
log "ls " & return & fromUnix
set fromUnix to do shell script "/bin/ls -l /Users/rmac/"
log "ls " & return & fromUnix
set fromUnix to do shell script "/bin/ls -l ~/Documents/PicToText.py"
log "ls " & return & fromUnix
try
-- /usr/bin/python -d -c
-- > ~/Desktop/scriptlog.txt
log "trying PicToText.py"
set toUnix to "(cd ~/Documents && /usr/bin/python -d -c '~/Documents/PicToText.py') &> ~/Desktop/scriptlog.txt "
set fromUnix to do shell script toUnix
log "first fromUnix is: " & fromUnix
on error errMsg
log " error..." & errMsg
end try
set fromUnix to do shell script "/bin/cat ~/Documents/PicToText.py"
log "cat " & return & fromUnix
set fromUnix to do shell script "/bin/cat ~/Desktop/scriptlog.txt "
log "cat " & return & fromUnix
end run(*pwd
/*)
(*id
uid=501(rmac) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),701(1)*)
(*python
*)
(*ls
total 45
drwxrwxr-x+ 39 root admin 1326 Mar 12 19:34 Applications
drwxr-xr-x+ 62 root wheel 2108 Mar 12 19:36 Library
drwxr-xr-x@ 2 root wheel 68 Oct 2 20:33 Network
drwxr-xr-x@ 4 root wheel 136 Jan 19 02:18 System
drwxr-xr-x 5 root admin 170 Feb 21 16:21 Users
drwxr-xr-x@ 7 root wheel 238 Mar 12 20:12 Volumes
drwxr-xr-x@ 38 root wheel 1292 Jan 19 02:22 bin
drwxrwxr-t@ 2 root admin 68 Oct 2 20:33 cores
dr-xr-xr-x 3 root wheel 4339 Mar 12 19:21 dev
lrwxr-xr-x@ 1 root wheel 11 Feb 20 21:30 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 Mar 12 19:43 home
-rw-r--r--@ 1 root wheel 313 Oct 4 17:05 installer.failurerequests
dr-xr-xr-x 2 root wheel 1 Mar 12 19:43 net
drwxr-xr-x@ 6 root wheel 204 Feb 20 21:31 private
drwxr-xr-x@ 63 root wheel 2142 Feb 20 21:31 sbin
lrwxr-xr-x@ 1 root wheel 11 Feb 20 21:30 tmp -> private/tmp
drwxr-xr-x@ 9 root wheel 306 Jan 19 02:13 usr
lrwxr-xr-x@ 1 root wheel 11 Feb 20 21:31 var -> private/var*)
(*ls
total 0
drwx------+ 8 rmac staff 272 Mar 12 20:21 Desktop
drwx---r-x+ 9 rmac staff 306 Mar 12 20:27 Documents
drwx------+ 6 rmac staff 204 Mar 12 19:34 Downloads
drwx------@ 54 rmac staff 1836 Mar 5 14:42 Library
drwx------+ 3 rmac staff 102 Feb 21 16:21 Movies
drwx------+ 3 rmac staff 102 Feb 21 16:21 Music
drwx------+ 3 rmac staff 102 Feb 21 16:21 Pictures
drwxr-xr-x+ 4 rmac staff 136 Feb 21 16:21 Public*)
(*ls
-rwxrwxrwx@ 1 rmac staff 56 Mar 11 18:05 /Users/rmac/Documents/PicToText.py*)
(*trying PicToText.py*)
(* error...The command exited with a non-zero status.*)
(*cat
#! /usr/bin/python
print("Hello, World from python!!!")*)
(*cat
File "<string>", line 1
~/Documents/PicToText.py
^
SyntaxError: invalid syntax*)Running Python in Automator