I have a Ruby script that I wrote that sorts some files in a jumble of directories based on it’s file extension. It would be very difficult to sort it using a GUI, and its easier for me to just put the file in the topmost directory and let the sorter do the work.
Problem is, I’m a bit of a noob to unix scripting. What I want to be able to do is be able to run that sorter script from anywhere on my computer, without having to
cd Desktop/Whatever/Foo
ruby sorterscript.rb
just write sortfolders at the commandline and have the program be run.
I’ve tested the script many times, and it works fine, I just want a bit more convenience.
Bonus: If possible, and not too difficult, it would be even better if I could have the program run, say, every hour automatically.
As far as your first question goes, you need to do couple of things:
Add a shebang line to your script (make it the first line of the script):
#!/usr/bin/ruby(or whatever the path to the Ruby interpreter’s executable is, I forget its exact location)Make the script executable, either via the Finder’s “Get Info” context menu, or via the command line, for example:
chmod 755 my_script.rbAdd the directory location of your script to the PATH environment variable to OS X’s launchd.conf file, as described here. You need to add this line:
setenv PATH /path/to/my/script:$PATH(substitute the real path to your script)As far as your bonus question goes, you can use cron to set up a recurring job. I never really do this, but here’s Apple’s cron man page to get you started.