When nzbget is started via launchagent, rvm ruby script doesn't work

This script does not work when launched from Nzbget if Nzbget is started
via LaunchAgent.
If I start Nzbget with the same arguments from the command line, it
works fine.

Here are the files and output:
-com.tv.nzbget.plist is located in ~/Library/Launchagents
-push.rb is the Nzbget post processing script
-test-rvm.txt is the output of the script for debugging
I am using RVM with my default ruby set to 2.1.1
for some reason, when started by launchd, Nzbget is using the system
ruby (2.0.0 on OS X 10.9)

when Nzbget is started by a launchagent

ruby 2.0.0p247 (2013-06-27 revision 41674)

when Nzbget is started from a terminal

(/usr/local/bin/nzbget -D -c /Users/Chancho/.nzbget.conf)

I get

ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0

If I explicitly call the rvm ruby path in my shebang, I still get the
same results.
I would like to be able to use my Rvm rubies and gemsets.
Any ideas how to fix it, or why this is happening?


I am calling my ruby script from a shell script that sets the Rvm ruby
I’d still like to know if there is a easier way. here is my script: