That does not:
I cannot tell webkit2png where to find the libraries (they are installed!)
MacMini:~ tjm$ python ~/webkit2png --help
usage: webkit2png [options] [ example.net/ …]
webkit2png http://google.com/ # screengrab google
webkit2png -W 1000 -H 1000 http://google.com/ # bigger screengrab of google
webkit2png -T http://google.com/ # just the thumbnail screengrab
webkit2png -TF http://google.com/ # just thumbnail and fullsize grab
webkit2png -o foo http://google.com/ # save images as “foo-thumb.png” etc
webkit2png - # screengrab urls from stdin
–version show program’s version number and exit
-h, --help show this help message and exit
-W WIDTH, --width=WIDTH
initial (and minimum) width of browser (default: 800)
-H HEIGHT, --height=HEIGHT
initial (and minimum) height of browser (default: 600)
–clipwidth=WIDTH width of clipped thumbnail (default: 200)
–clipheight=HEIGHT height of clipped thumbnail (default: 150)
-s SCALE, --scale=SCALE
scale factor for thumbnails (default: 0.25)
-m, --md5 use md5 hash for filename (like del.icio.us)
-o NAME, --filename=NAME
save images as NAME.png,NAME-thumb.png etc
-F, --fullsize only create fullsize screenshot
-T, --thumb only create thumbnail sreenshot
-C, --clipped only create clipped thumbnail screenshot
-d, --datestamp include date in filename
-D DIR, --dir=DIR directory to place images into
It’s related to this:
Does anyone know how to tell AppleScript to use libraries not beeing in its “do shell”-path environment???
I’ve had this problem once using nmap or lynx (don’t know which one anymore) binaries. But I was able to build an application bundle and placed the libs within the bundle, configured as needed and it worked.
But this was not Python. And I am not so much familiar with Python on the Mac as I wanted to be.
Model: Mac-Mini 1.42 G4 80/250 GB HD 1GB RAM
Browser: Firefox 126.96.36.199
Operating System: Mac OS X (10.4.8)
It says that Python 2.4 is required, but Mac OS X seems to come with 2.3.5 (on my machine with Mac OS X 10.4.8 installed, at least). Did you install a newer version yourself and adjust your $PATH to that instead?
Check/post the results for these (run the first two from the command line):
do shell script "which python"
do shell script "echo $PATH"
The solution here, if I’m understanding the problem correctly, is to
. always use full path to executable when using do shell script
do shell script "which python"
do shell script "echo $PATH"
The Python script has been executed. The error messages returned was sent by it, not by AppleScript.
Problem is that the lib “pyobjc” is not and the “do shell script”-environment is different from the Terminal.
The $PATHs should be added systemwide for the usage in scripts like this maybe. Would this be a good idea? If so, how, or better where, to do it?
So the problem can be reduced to the point, how to change AppleScript’s environment $PATH defaults. And, if we want to be userfriendly, how to change them using AppleScript itself?
TN2065: do shell script in AppleScript
Q: My command works fine in Terminal, but when I try to use it in do shell script, I get an error about “command not found.” What’s going on?
A: There are two possibilities. First, do shell script always uses /bin/sh to interpret your command, not your default shell, which Terminal uses. (To find out what your default shell is, say echo $SHELL in Terminal.) While some commands are the same between shells, others are not, and you may have used one of them. If you write your do shell script scripts in Terminal first, always use sh. You can start sh by typing /bin/sh; type exit to get back to your normal shell.
Second, when you use just a command name instead of a complete path, the shell uses a list of directories (known as your PATH) to try and find the complete path to the command. For security and portability reasons, do shell script ignores the configuration files that an interactive shell would read, so you don’t get the customizations you would have in Terminal. Use the full path to the command, for example, /sbin/ifconfig instead of just ifconfig. To find the full path in Terminal, say which command-name, for example, which ifconfig; to see the list of places do shell script will search, say do shell script “echo $PATH”.
Q: Where does the shell environment come from ” environment variables, working directory, and so on?
A: do shell script inherits the environment of its parent process. Because of how scripting additions like do shell script work, the parent process is the application for the tell block surrounding the do shell script call. If there is no surrounding tell block, or if you tell me, the parent is the application running the script.
The environment covers the working directory, any environment variables, and several other attributes ” see the execve(2) man page for a complete list. As mentioned in Issuing Commands, do shell script does not read the configuration files that an interactive shell running in Terminal would.
Any application launched from the Finder gets the same default environment: a working directory of / and the environment variables HOME, LANG, PATH, USER, and SHELL. (You can define more environment variables if you wish; see
Technical Q&A QA1067, Setting environment variables for user processes for details.) Most applications do not change their environment, but relying on this is a maintenance risk.
osascript(1) inherits its environment from the shell it’s run from: the working directory is the working directory of the shell; any environment variables defined in the shell will also be defined in osascript, and therefore in do shell script.
Based on that second answer, trying to change the PATH for /bin/sh is not reliable.
The solution here is to
. (I’ll repeat this over and over. ;)) always use full path to executable when using do shell script
You are the BEST!
do shell script "/Library/Frameworks/Python.framework/Versions/Current/bin/python2.4 /Users/tjm/webkit2png -F -W 1024 -d -D ~/Pictures http://www.macscripter.net"
What a hack!
By this thread you can make your own Paparazzi! application that works interfaceless in scripts.
Thank you Bruce! To all, njoy and have fun!
What do you get when you run this in Terminal:
and this in Script Editor:
set py_text to "import sys
set py_com to ReplaceText(py_text, return, ASCII character 10)
do shell script "python -c " & quoted form of py_com
on ReplaceText(t, s, r)
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to s
set temp_list to text items of t
set AppleScript's text item delimiters to r
set temp_text to temp_list as string
set AppleScript's text item delimiters to utid
Quite different results:
MacMini:~ tjm$ python
Python 2.4.4 ( #1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
[‘’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/TurboGears-0.8.9-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/TestGears-0.2-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/FormEncode-0.4-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/cElementTree-1.0.5_20051216-py2.4-macosx-10.4-ppc.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/elementtree-1.2.6-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/json_py-3.4-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1457-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/CherryPy-2.1.1-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/kid-0.8-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/setuptools-0.6c5-py2.4.egg’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python24.zip’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-darwin’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/plat-mac/lib-scriptpackages’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/lib-tk’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/lib-dynload’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Py2App’, ‘/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/PyObjC’, ‘/Users/tjm/Library/Python/2.4/site-packages’]
“[‘/’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python23.zip’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-darwin’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/lib-scriptpackages’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages’, ‘/System/Library/Frameworks/Python.framework/Versions/2.3/Extras/lib/python’]”
That’s where the problem resides. As I already detected. But how to solve it? That’s the question.
As Bruce wrote, I think, is that your updated version of Python is not running in the ‘do shell script’. With ‘do shell script’ you get the default path which is the path to your old version of python. So, you want to change things so that your ‘do shell script’ runs the new Python.
What I did was match them exactly by adding a ~/.MacOSX/environment.plist file. But first as Bruce wrote, check your paths. In Terminal and Script Editor:
What I did was just copy the PATH value from Terminal and enter it in the environment.plist file. So I would copy the result to:
<?xml version="1.0" encoding="UTF-8"?>
Note that /usr/local/bin/ contains a link to the updated version of python. This path I got from Terminal is updated because I add a ~/.profile file for bash. First, I would check if you have /usr/local/bin/python and see if the installer created the link.
This is confusing, so if you plan to change the PATH and need more help write back.
Edited: I forgot to mention that after creating or editing the environment.plist file, you need to relogin. the os reads the updated environment varibles from environment.plist at login.
Thanks a lot! That’s exactly the information I was looking for.
I will give it a try tomorrow and send a reply if it was really helpful or not! It seems to be (helpful)!