How to source a file from launchctlEnvironment variables in Mac OS XGet the source directory of a Bash script from within the script itselfHow can I Remove .DS_Store files from a Git repository?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How to concatenate string variables in BashHow to access environment variable values?How do I delete an exported environment variable?How do I install pip on macOS or OS X?launchctl process showing non-zero exit code
Would glacier 'trees' be plausible?
Find the cheapest shipping option based on item weight
Adjacent DEM color matching in QGIS
Where are the "shires" in the UK?
How did the Venus Express detect lightning?
Out of scope work duties and resignation
Is there an official reason for not adding a post-credits scene?
Can my company stop me from working overtime?
How can I support myself financially as a 17 year old with a loan?
Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?
What if the end-user didn't have the required library?
Are Finitely generated modules over a ring also finitely generated over a subring containing the identity?
Where can I go to avoid planes overhead?
Manager is threatening to grade me poorly if I don't complete the project
A factorization game
Has the Hulk always been able to talk?
In Stroustrup's example, what does this colon mean in `return 1 : 2`? It's not a label or ternary operator
How to safely wipe a USB flash drive
Why is "breaking the mould" positively connoted?
Should homeowners insurance cover the cost of the home?
Identifying characters
Introducing Gladys, an intrepid globetrotter
exec command in bash loop
What does "Managed by Windows" do in the Power options for network connection?
How to source a file from launchctl
Environment variables in Mac OS XGet the source directory of a Bash script from within the script itselfHow can I Remove .DS_Store files from a Git repository?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How to concatenate string variables in BashHow to access environment variable values?How do I delete an exported environment variable?How do I install pip on macOS or OS X?launchctl process showing non-zero exit code
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to source
a file from a launch agent
, but it's unclear how to accomplish that (or if it's even possible). I know it's easy to setenv
for single variables, but I need to bring in a bunch of them, so source
is what I need.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
This loads and starts without any issue it seems:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
But when I printenv
none of my sourced environment variables show up. If manually I do:
$ source /path/to/source/my_file.sh
$ printenv
Then all of the variables show up. Why doesn't the launchctl
agent seem to load the variables into my environment?
bash macos environment-variables launchctl
add a comment |
I'm trying to source
a file from a launch agent
, but it's unclear how to accomplish that (or if it's even possible). I know it's easy to setenv
for single variables, but I need to bring in a bunch of them, so source
is what I need.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
This loads and starts without any issue it seems:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
But when I printenv
none of my sourced environment variables show up. If manually I do:
$ source /path/to/source/my_file.sh
$ printenv
Then all of the variables show up. Why doesn't the launchctl
agent seem to load the variables into my environment?
bash macos environment-variables launchctl
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
1
Whatsource
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could usesource
there it would set the variables for the launchd process, not for your shell processes.
– Gordon Davisson
Mar 23 at 0:42
Launchd runs programs. Thesource
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching yourmy.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?
– Kurtis Rader
Mar 23 at 1:35
@GordonDavisson: That makes sense, but then why then would I have some apps thatsetenv
from a launch agent? Or rather, why would it be useful rather than setting it in~/.bash_profile
?
– ctfd
Mar 23 at 3:35
@KurtisRader: I have an app (not one I created) that requires it to usesource initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.
– ctfd
Mar 23 at 3:39
add a comment |
I'm trying to source
a file from a launch agent
, but it's unclear how to accomplish that (or if it's even possible). I know it's easy to setenv
for single variables, but I need to bring in a bunch of them, so source
is what I need.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
This loads and starts without any issue it seems:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
But when I printenv
none of my sourced environment variables show up. If manually I do:
$ source /path/to/source/my_file.sh
$ printenv
Then all of the variables show up. Why doesn't the launchctl
agent seem to load the variables into my environment?
bash macos environment-variables launchctl
I'm trying to source
a file from a launch agent
, but it's unclear how to accomplish that (or if it's even possible). I know it's easy to setenv
for single variables, but I need to bring in a bunch of them, so source
is what I need.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.sourcerer</string>
<key>ProgramArguments</key>
<array>
<string>source</string>
<string>my_file.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/path/to/source</string>
</dict>
</plist>
This loads and starts without any issue it seems:
$ launchctl load ~/Library/LaunchAgents/my.sourcerer.plist
$ launchctl start ~/Library/LaunchAgents/my.sourcerer.plist
But when I printenv
none of my sourced environment variables show up. If manually I do:
$ source /path/to/source/my_file.sh
$ printenv
Then all of the variables show up. Why doesn't the launchctl
agent seem to load the variables into my environment?
bash macos environment-variables launchctl
bash macos environment-variables launchctl
asked Mar 22 at 23:52
ctfdctfd
144112
144112
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
1
Whatsource
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could usesource
there it would set the variables for the launchd process, not for your shell processes.
– Gordon Davisson
Mar 23 at 0:42
Launchd runs programs. Thesource
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching yourmy.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?
– Kurtis Rader
Mar 23 at 1:35
@GordonDavisson: That makes sense, but then why then would I have some apps thatsetenv
from a launch agent? Or rather, why would it be useful rather than setting it in~/.bash_profile
?
– ctfd
Mar 23 at 3:35
@KurtisRader: I have an app (not one I created) that requires it to usesource initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.
– ctfd
Mar 23 at 3:39
add a comment |
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
1
Whatsource
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could usesource
there it would set the variables for the launchd process, not for your shell processes.
– Gordon Davisson
Mar 23 at 0:42
Launchd runs programs. Thesource
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching yourmy.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?
– Kurtis Rader
Mar 23 at 1:35
@GordonDavisson: That makes sense, but then why then would I have some apps thatsetenv
from a launch agent? Or rather, why would it be useful rather than setting it in~/.bash_profile
?
– ctfd
Mar 23 at 3:35
@KurtisRader: I have an app (not one I created) that requires it to usesource initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.
– ctfd
Mar 23 at 3:39
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
1
1
What
source
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could use source
there it would set the variables for the launchd process, not for your shell processes.– Gordon Davisson
Mar 23 at 0:42
What
source
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could use source
there it would set the variables for the launchd process, not for your shell processes.– Gordon Davisson
Mar 23 at 0:42
Launchd runs programs. The
source
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching your my.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?– Kurtis Rader
Mar 23 at 1:35
Launchd runs programs. The
source
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching your my.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?– Kurtis Rader
Mar 23 at 1:35
@GordonDavisson: That makes sense, but then why then would I have some apps that
setenv
from a launch agent? Or rather, why would it be useful rather than setting it in ~/.bash_profile
?– ctfd
Mar 23 at 3:35
@GordonDavisson: That makes sense, but then why then would I have some apps that
setenv
from a launch agent? Or rather, why would it be useful rather than setting it in ~/.bash_profile
?– ctfd
Mar 23 at 3:35
@KurtisRader: I have an app (not one I created) that requires it to use
source initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.– ctfd
Mar 23 at 3:39
@KurtisRader: I have an app (not one I created) that requires it to use
source initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.– ctfd
Mar 23 at 3:39
add a comment |
1 Answer
1
active
oldest
votes
Based on the comments to the question I'm going to go out on a limb and try to answer the question.
It seems you want to launch a program when you login rather than manually after you open your first terminal session. The solution is to create a script that includes the necessary source
command to initialize the environment. Then make that script pathname the first arg of your ~/Library/LaunchAgents/my.sourcerer.plist config.
You could also statically set those vars via launchctl setenv
. But I would not recommend that approach because it obviously isn't dynamic. That is, if the output of the source
d script ever changes the statically set env vars inherited by every process would not change.jj
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put thesource
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.
– Kurtis Rader
Mar 24 at 23:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309203%2fhow-to-source-a-file-from-launchctl%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Based on the comments to the question I'm going to go out on a limb and try to answer the question.
It seems you want to launch a program when you login rather than manually after you open your first terminal session. The solution is to create a script that includes the necessary source
command to initialize the environment. Then make that script pathname the first arg of your ~/Library/LaunchAgents/my.sourcerer.plist config.
You could also statically set those vars via launchctl setenv
. But I would not recommend that approach because it obviously isn't dynamic. That is, if the output of the source
d script ever changes the statically set env vars inherited by every process would not change.jj
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put thesource
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.
– Kurtis Rader
Mar 24 at 23:13
add a comment |
Based on the comments to the question I'm going to go out on a limb and try to answer the question.
It seems you want to launch a program when you login rather than manually after you open your first terminal session. The solution is to create a script that includes the necessary source
command to initialize the environment. Then make that script pathname the first arg of your ~/Library/LaunchAgents/my.sourcerer.plist config.
You could also statically set those vars via launchctl setenv
. But I would not recommend that approach because it obviously isn't dynamic. That is, if the output of the source
d script ever changes the statically set env vars inherited by every process would not change.jj
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put thesource
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.
– Kurtis Rader
Mar 24 at 23:13
add a comment |
Based on the comments to the question I'm going to go out on a limb and try to answer the question.
It seems you want to launch a program when you login rather than manually after you open your first terminal session. The solution is to create a script that includes the necessary source
command to initialize the environment. Then make that script pathname the first arg of your ~/Library/LaunchAgents/my.sourcerer.plist config.
You could also statically set those vars via launchctl setenv
. But I would not recommend that approach because it obviously isn't dynamic. That is, if the output of the source
d script ever changes the statically set env vars inherited by every process would not change.jj
Based on the comments to the question I'm going to go out on a limb and try to answer the question.
It seems you want to launch a program when you login rather than manually after you open your first terminal session. The solution is to create a script that includes the necessary source
command to initialize the environment. Then make that script pathname the first arg of your ~/Library/LaunchAgents/my.sourcerer.plist config.
You could also statically set those vars via launchctl setenv
. But I would not recommend that approach because it obviously isn't dynamic. That is, if the output of the source
d script ever changes the statically set env vars inherited by every process would not change.jj
answered Mar 23 at 5:04
Kurtis RaderKurtis Rader
3,434610
3,434610
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put thesource
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.
– Kurtis Rader
Mar 24 at 23:13
add a comment |
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put thesource
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.
– Kurtis Rader
Mar 24 at 23:13
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
How would I be able to confirm that the environment variables that I source in the script are set when I login?
– ctfd
Mar 24 at 6:14
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put the
source
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.– Kurtis Rader
Mar 24 at 23:13
When I wrote "login" above I meant logging in to the desktop environment after booting the computer. And I assumed you would launch the program that needs the env vars from the same script you had launchd run. If you want to be able to run that program from an interactive shell you'll need to put the
source
command in the appropriate shell config file; e.g., ~/.bashrc. I get the distinct sense you're trying to make a simple problem more complicated than it needs to be.– Kurtis Rader
Mar 24 at 23:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309203%2fhow-to-source-a-file-from-launchctl%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Environment variables in Mac OS X
– duskwuff
Mar 22 at 23:58
1
What
source
does is run commands from a file in the current shell, and that doesn't make sense except in a shell; launchd isn't a shell, so it doesn't make sense there. But even if you could, I don't think it would do what you want. Each process has its own environment variables (though child processes start with a copy of their parent's environment), so if you could usesource
there it would set the variables for the launchd process, not for your shell processes.– Gordon Davisson
Mar 23 at 0:42
Launchd runs programs. The
source
command is a shell builtin. It is not a program. If you look at /var/log/system.log you should see error messages related to launching yourmy.sourcerer.plist
config. Furthermore, you can't modify the environment of your current shell (or any other already running process) setting an env var in a process created by launchd. What is it you're really trying to do?– Kurtis Rader
Mar 23 at 1:35
@GordonDavisson: That makes sense, but then why then would I have some apps that
setenv
from a launch agent? Or rather, why would it be useful rather than setting it in~/.bash_profile
?– ctfd
Mar 23 at 3:35
@KurtisRader: I have an app (not one I created) that requires it to use
source initialize
to setup environment variables before it runs. I was hoping that I could streamline the process by having the environment variables automatically set at boot so that process was not necessary.– ctfd
Mar 23 at 3:39