One other shell() question

It appears that shell()'s working directory is “the folder” property, as stored in preferences. However, changing “the folder” on the fly does not change the initial working directory. Is that the way it’s supposed to work? If so, that’s fine, I can always stick a cd at the beginning of all my commands :wink:

How did you set the folder and what did you set it to?

Here’s the code I ran as an experiment

put the folder     #=>"/path/to/eggplant/default/folder"
put shell("pwd") #=>"/path/to/eggplant/default/folder"
set the folder to "/somewhere/else"
put the folder     #=>"/somewhere/else"
put shell("pwd") #=>"/path/to/eggplant/default/folder"

It makes some sense to me that shell() would be a special case and that it would default either to the user’s home directory or to the working folder of the application at startup. Shell is a call out to the OS which has it’s own environmental defaults and history that I wouldn’t expect to be influenced by SenseTalk commands – the scope of those commands would be confined to Eggplant/SenseTalk. So I think that this is the correct behavior, but I’m going to consult an expert to be sure.

Hmm… I’m not seeing this. When I set the folder, it’s reflected in the shell:

set the folder to "/"
put shell("pwd") -- /
set the folder to "/Users"
put shell("pwd") -- /Users

That’s how it should work, picking up the current setting of “the folder” as the initial working directory in the shell. I’m not sure why you’re not seeing this, although if you try to set the folder to a non-existent directory it will fail (nothing will happen).

On a related note, if you need to set other environment variables, note that the open process command allows you to specify a number of different options, including a set of environment variables, like this:

open process "/bin/sh" with options (environment:(CWD:"/", FOO:"abcd"))
write "echo $FOO" & return to process "/bin/sh"
read from process "/bin/sh" until end
put it

I played with this approach to see if it could solve your problem, but I couldn’t find any environment variable that can be set to change the initial working directory of the shell (the CWD entry shown above didn’t do it).

It wasn’t behaving like that yesterday :wink:

Thanks!

Allen