webkit2png works fine in Terminal, but not in AppleScript...

Hello everyone,

I’m using the command line tool called webkit2png, which grabs screenshots of websites. For example, to get Google you’d type…

That works fine in Terminal. All I’m trying to do is get this single line into an AppleScript. Here’s what I have:

do shell script "cd ~; python webkit2png-0.4.txt.sh http://www.google.com"

Strangely, this does not work - the error is that it can’t find the PyObjC library files. You can find this error in the very beginning of the webkit2png script…

Why would it work in Terminal but fail in AppleScript? Any help here would be really appreciated.

Model: Mac Mini Core Solo
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Applescript typically uses the “sh” shell, whereas OS X 10.2 uses tcsh and 10.3 and up, bash. Try setting a different shell in the beginning, with something like “/bin/bash” at the beginning of your shell script command.

eta: I don’t know if this will work; I hope it helps :).


Here’s an Apple faq article:



I ran this…

do shell script "echo $SHELL"

And got this result…

I went to Terminal Preferences and clicked the radio button for “bin/bash” and it, too, started returning the same error. I switched the radio button back and it still doesn’t work. So now, neither works with webkit2png :frowning:

I wish it wasn’t this hard. I’m sorry to be a bother but if anyone has ideas here I would appreciate it.

hi steve,

did you install pyobjc? if so, do you know where it lives? if you can include that in the path, i think you’ll be set (basically this is what everyone else is saying). i’m going to install it now and check this out. it seems pretty neat.


Yeah, I have installed pyobjc many times but it doesn’t seem to be finding it (not even Terminal, as of this morning). I think pyobjc is the “py2app” folder in Library/Python/2.3/site-packages, though I’m not sure how to tell the shell that…

Were you able to get webkit2png to work, waltr? I’m just curious.

hi steve,

phew! i finally got this to work! here are the details of my setup:

10.4.7 on an older G4. python 2.3.5

and here’s how i did it. i went to the sourceforge site for pyobjc and downloaded the SOURCE for the pyobjc. i had tried to install the binaries, but i feel like there was an extra step somewhere that i could not find documented.

once i had the source on my desktop, i ‘cd’d’ in there in Terminal and typed:

sudo python setup.py bdist_mpkg --open

and then i checked the folder: /usr/lib/python2.3/site-packages/

and found the Py2App, Py2App.pth, PyObjC, PyObjC.pth files and directories had been installed. these had NOT been installed by the binary package.

now i can use webkit2png from either the Terminal or from AppleScript. i changed your script slightly:

do shell script "cd ~; /usr/bin/python ~/bin/webkit2png-0.4.txt.sh http://www.google.com"

since i like to keep these kinds of things in my /bin.

NOTE: here is a test that i used after the install. at the Terminal, open the Python interpreter like this:

$ python

and at the >> prompt type:

import Foundation.

if that works, you should be able to use webkit2png (or any other pyobjc program).


Thanks waltr, I did everything you said and it looks like Terminal is working again. Applescript is still returning the same error though. The python interpreter in Terminal returns “Syntax Error: invalid syntax” when I type “Import Foundation.” It’s still an improvement, though, so thank you again.

BTW, my site-packages folder has only these…

py2app (folder)

hi steve,

do you have multiple versions of Python installed on your Mac? i saw some mention of problems w/ that in my search yesterday.

try this:

in the Terminal type:

which python

and then run this:

set a to (do shell script "which python")
display dialog a

and compare. also, i’m not sure why your pyobjc libraries seem different than mine. if i get time (it is Christmas!) this weekend, i’ll perform the same operation on my Mac Mini here at home for comparison.

EDITED to add:

i just realized that i did do one other thing. after i cd’d into the directory where the source code for pyobjc, i did:

sudo python setup.py --install

and then i got a message to do:

sudo python setup.py bdist_mpkg --open

i think that’s probably why i’ve got more in my library than you seem to. sorry for forgetting a step!