3

I've done this once and I'm trying to do it on a new computer and I can't see what I'm doing wrong.

I have a ruby script in my user folder named forecast.rb. I have set it to executable (a+x). It writes a line out to another file called .weather.txt.

I want to run forecast.rb every 5 minutes.

I have a plist file named com.jwhite.forecast_tmux.plist. That file looks like:

<?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>com.jwhite.forecast_tmux</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/jwhite/forecast.rb</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
</dict>
</plist>

This file is located in ~/Library/LaunchAgents. And after moving it there I ran Launchctl load -w ~/Library/Launchagents/com.jwhite.forecast_tmux.plist.

If I run forecast.rb (./forecast.rb) it runs fine. But my launchd is not executing.

What am I missing?

EDIT:

I've started using LaunchControl and got the error.

/Users/jwhite/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- geocoder (LoadError)
from /Users/jwhite/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/jwhite/forecast.rb:3:in `<main>'

But when I run this from the terminal everything executes fine. So launchctl can't read in Ruby Gems?

9
  • What is the first line of the rb script?
    – mmmmmm
    Jul 5, 2015 at 15:51
  • The label must match the file name without the .plist.
    – fd0
    Jul 5, 2015 at 15:53
  • @fd0 It does actually. That was a bad copy/paste from when I did this previously. I've edited the description to show what I really am doing. Jul 5, 2015 at 16:24
  • @Mark the first line is #!/Users/jwhite/.rvm/rubies/ruby-2.2.1/bin/ruby Jul 5, 2015 at 16:25
  • Is your username jhwhite or jwhite ? Look over what you have presented.
    – fd0
    Jul 5, 2015 at 16:29

1 Answer 1

1

I had the same issue, trying to run a script on an interval using LaunchControl (great app, check it out). Will copy and paste straight from the source that helped me:

For GUI programs the default shell environment scripts are ignored, and therefore RVM managed ruby versions.

The workaround is to define them via launchctl. Those values are gone though after a reboot, so I put them in .bash_profile since I open a shell anyhow all the time, see below.

launchctl setenv GEM_HOME ~/.rvm/gems/ruby-2.2.1 launchctl setenv GEM_PATH ~/.rvm/gems/ruby-2.2.1:/Users/markus/.rvm/gems/ruby-2.2.1@global

All more permanent solutions (e.g. launchd.conf) don't work anymore in 10.10. Hope that helps anyone who ran into a similar issue.

In my case I just set it up the correct GEM_HOME and PATH in LaunchControl.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .