I have the following Applescript in a workflow assigned to a service hotkey that opens a terminal in a given Finder window:
tell application "Finder" set myWin to window 1 set thePath to (quoted form of POSIX path of (target of myWin as alias)) tell application "Terminal" activate tell window 1 do script "cd " & thePath end tell end tell end tell
I would like to set an environment variable before the terminal is invoked so that when
.bash_profile is sourced, an if statement checking for the existence of said environment variable passes.
I've seen methods to access environment variables, such as this, but nothing that sets environment variables for the following shell session.
I have tried to change the terminal line to
do script "my_env_var=some_value; cd " & thePath, but I need it set before the session starts. I also tried to set the variable in a
do script before the one that opens the shell I want to use:
do script "my_env_var=some_value" do script "cd " & thePath
But this just opens two shells and does the same as before.
Is there a way to accomplish setting this environment variable, or perhaps determining if the terminal was invoked by this service rather than another method?