Problem with downloading web-pages as pictures [$PATH]

That works:

That does not:

I cannot tell webkit2png where to find the libraries (they are installed!)

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
AppleScript: Current
Browser: Firefox
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):

which python
echo $PATH
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"
-->	"/usr/bin/python"
do shell script "echo $PATH"
-->	"/usr/bin:/bin:/usr/sbin:/sbin"

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?



Reminder: TN2065: do shell script in AppleScript

Based on that second answer, trying to change the PATH for /bin/sh is not reliable.

The solution here is to always use full path to executable when using do shell script. (I’ll repeat this over and over. ;))

Yeah Bruce

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"

did it!!!

What a hack!



It works:

By this thread you can make your own Paparazzi! application that works interfaceless in scripts.

Thank you Bruce! To all, njoy and have fun!


Hi Tom,

What do you get when you run this in Terminal:

import sys
print sys.path

and this in Script Editor:

set py_text to "import sys
print sys.path"
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
	return temp_text
end ReplaceText



Quite different results:

From Terminal:

From Scripteditor:

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:

echo $PATH

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"?> PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/kel

where “/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/kel”.

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)!