Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Help request: how to run automatically on OS X #372

Open
jgclark opened this issue May 21, 2015 · 4 comments
Open

Help request: how to run automatically on OS X #372

jgclark opened this issue May 21, 2015 · 4 comments

Comments

@jgclark
Copy link
Contributor

jgclark commented May 21, 2015

I'd like slogger to run automatically once or twice a day on my MacBook running OS X.
Problem is that I currently have three versions of Ruby on my system including 1.8.7 and 2.2.1, niether of which slogger will run with. So I say "rvm use system" which switches to a different version, though I don't know how to find out which one (as "rvm current" just replies "system").

When I create this little script:

!/bin/bash

rvm use system ###
/Users/jonathan/Library/Scripts/slogger/slogger

It won't run from the shell, saying:

"RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use /bin/bash --login as the command."

I know how to create and set launchd jobs; but I don't know how to set the ruby version for the created process if I can't include it in a script in this way. Thanks.

@larryhynes
Copy link
Contributor

As best I can figure out from here rvm supports per-folder .ruby-version files. So putting a file named .ruby-version containing the Ruby version that you want, probably 1.9.3, in your Slogger folder should set the Ruby version for Slogger to use.

To see what version of Ruby rvm considers to be the system Ruby, running ruby --version after rvm use system should return the version details for the system ruby.

To use the rvm use system command that you want to use from the script you want to run you can change the shebang line (the line at the top of the script) to #!/bin/bash --login, or #!/bin/bash -l to invoke the bash shell as a login one, as is suggested in the output you're currently getting.

Let me know how you get on and we'll see if we can get you up and running.

@ttscoff
Copy link
Owner

ttscoff commented May 21, 2015

Use rvm-auto-ruby instead of ruby in the launchd plist. That will pick
up the .ruby-version (use 2.0) in the slogger folder and execute with
the appropriate gem environment as created by bundle install.

On 21 May 2015, at 11:29, Larry Hynes wrote:

As best I can figure out from here
rvm supports per-folder .ruby-version files. So putting a file named
.ruby-version containing the Ruby version that you want, probably
1.9.3, in your Slogger folder should set the Ruby version for
Slogger to use.

To see what version of Ruby rvm considers to be the system Ruby,
running ruby --version after rvm use system should return the
version details for the system ruby.

To use the rvm use system command that you want to use from the
script you want to run you can change the shebang line (the line at
the top of the script) to #!/bin/bash --login, or #!/bin/bash -l
to invoke the bash shell as a login one, as is suggested in the output
you're currently getting.

Let me know how you get on and we'll see if we can get you up and
running.


Reply to this email directly or view it on GitHub:
#372 (comment)

@jgclark
Copy link
Contributor Author

jgclark commented May 25, 2015

Thanks, both. ruby --version gives 2.0.0p481.

It turns out I can't seem to get the launchd plist right after all. This is my attempt. Can you please spot what I'm doing wrong? Thanks.

<?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.clarksonline.daily_slogger</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/jonathan/.rvm/bin/rvm-auto-ruby</string>
        <string>/Users/jonathan/Library/Scripts/slogger/slogger</string>
    </array>
    <key>StandardOutPath</key>
    <string>/tmp/daily_slogger.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/log/daily_slogger.log</string>
    <key>Debug</key>
    <true/>
    <key>OnDemand</key>
    <true/>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>5</integer>
        <key>Minute</key>
        <integer>15</integer>
    </dict>
</dict>
</plist>

@djmonta
Copy link

djmonta commented Aug 30, 2015

I had the same problem, but just simply added <string>/bin/sh</string> in ProgramArguments.

This is my plist.

<?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.brettterpstra.Slogger</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>/Users/monta/.anyenv/envs/rbenv/shims/ruby</string>
        <string>/Users/monta/Documents/Slogger/slogger</string>
        <string>-s</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>23</integer>
        <key>Minute</key>
        <integer>50</integer>
    </dict>
</dict>
</plist>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants