'Do shell script' error [Path; ImageMagick]

i’ve finished my script. it runs silently and very smooth. and, best of all, very fast.
it waits when it needs to, it renames the files if they are already in use, it keeps a log of errors, and does the resizing beautifully, but…

i’m on MacOSx 10.4.7, with the latest versions of Imagemagick and Ghostscript (acording to fink).
when i was messing around in the Terminal, trying to understand how to tell Imagemagick to resize and everything, it could process any kind of file i wanted. but when applescript does de “do shell script” it cannot process EPS (nor illustrator, nor photoshop)…
i typed the exact string in the script in the Terminal, and the Terminal processes the images without a problem.

-this is the error message:

sh: line 1: gs: command not found
sh: line 1: gs: command not found
convert: no decode delegate for this image format `/files/EPSi.eps’.

-this is the processing part of the code:

on process_files(source_file, file_name, pwg_folder, tn_folder)
		set the pwg_path to ((pwg_folder as string) & file_name) as string
		set the tn_path to ((tn_folder as string) & "tn_" & file_name) as string
		set original to POSIX path of source_file
		set pwg to POSIX path of pwg_path
		set tn to POSIX path of tn_path
		with timeout of 180 seconds
			do shell script "/sw/bin/convert " & original & " -resize 400x400 -colorspace RGB " & pwg & " && /sw/bin/convert " & pwg & " -resize 120x120 " & tn
		end timeout
	on error the error_message number the error_number
		set the error_text to "Error: " & the error_number & ". " & the error_message
		my write_error_log(the error_text)
	end try
	return 0
end process_files

i belive that for some odd reason, applescript isn’t using the ‘codec’ from Ghostscript (thats the GS?), so it cannot read nor write EPSs… but why?
and, more important, how do i make applescript to read and write EPSs???

this one really left me stupid…

thanks to everyone, you’ve been too much helpfull.

Run this in Script Editor and post the result:

do shell script "which gs"

“no gs in /usr/bin /bin /usr/sbin /sbin”

that was the reply.
but if I can use it in the Terminal without a problem, why is it that applescript can’t find it?
should I move the GS? or move something else?
or is there something to append to my code to make it look for the right address for the gs?


you need to run the command from terminal then (which gs).

What happens is that when you launch terminal it loads your ~/.profile file (which has an updated $PATH variable in it which fink put there when you installed it. the problem is your script doesn’t know the path /sw/bin.

In a lot of shell scripts i see the full path to the executable is usually set in a variable at the top of the script just incase on a different system it is in a different spot, it is easier to change the one occurance at the top of the script.

so in your case it would be
set ghostScript to “/sw/bin/gs”

do shell script ghostScript & " --flags --and --stuff"

ok. but my problem is that ghostscript is not the executabe i’m calling from my script.
i’m doing a ‘convert’ command to the files, but just for the EPSs, it needs some kinda ‘codec’ that lies in the GS.
and my script can’t locate it…

what can i do?


.it throws an error about not finding a gs command first, then an error comes from an error comes from convert.

If your commands run in Terminal but not from do shell script, then something is different between theses two enviroments; differences in $PATH are a very common problem.

Run this from Terminal and post the result:

which gs


was the result…
can i fiz the enviroments?

Does this work any better?

do shell script "alias gs=/sw/bin/gs; /sw/bin/convert " & original & " -resize 400x400 -colorspace RGB " & pwg & " && /sw/bin/convert " & pwg & " -resize 120x120 " & tn


since I’ve a PC at home, and a Mac at work, and all my life i’ve been dealing with PCs and Windows, I just made it the Windows-way. and, to my surprise, it worked.
i just copied all the files from “/sw/bin” to “/bin”.
it isn’t too much space on disk, so i didn’t mind. and that way, when Terminal wants the executables, it picks the “/sw/bin” ones… when Do Shell script wants them, it picks up the “/bin” ones…

i know. it’s a shitty solution. but the script is meant to run only on the Server of the office, so I don’t mind.

do you think it could cause any problem?

thanks for all the help.

Are you sure that’s how your path is setup?

You should really fix the actual problem, instead of taking a chance on introducing new ones.

Alternatively, if you don’t want to fix the PATH for the script that has the actual problem, then you could at least use a link (man ln) instead of copying the actual files.

well, i deleted the files i copied, so i’m right where i left.

the " alias gs=/sw/bin/gs; " string didn’t work…

any more ideas?
thanks to everyone.


do shell script "PATH=$PATH:/sw/bin; /sw/bin/convert " & original & " -resize 400x400 -colorspace RGB " & pwg & " && /sw/bin/convert " & pwg & " -resize 120x120 " & tn

Edit: Removed two spaces.

nope, sorry. same error…

By same error, do you mean this?


Well, I would say the problem is with GhostScript.

but when I copied the files to ‘/bin’, or when I make the convertion from the Terminal… GhostScript doesn’t give me any trouble…
that’s why I’m really in the dark here…
until it gives me a problem, i think i’m gonna go with the shitty solution of the "copy-paste’.

thanks to everyone that helped me.

Still, why not use a hard link instead?

/bin/ln /sw/bin/gs /bin/gs