I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).
There's an option to add applications etc that need to start at login, you could try writing a shell script or an apple script thing that launches terminal and runs ruby my_ruby_script.rb, or possibly even just add my_ruby_script.rb to this list after adding a #!/bin/env ruby line to the top of that file. http://support.apple.com/kb/HT2602?viewlocale=en_US gives precise instructions as to how to add an application to be started at login.
If you need to use AppleScript to actually start a terminal application (I believe this is not the case, but I am not in front of my mac now and hence can't test), just create an applescript file with something like
do shell script "ruby <path>/my_ruby_script.rb"
Hope this helps
As Panda said, add:
#!/bin/env ruby
to the begining of the file, and then you could add a reference to your file inside ~/.bashrc or ~/.profile or even /etc/profile , depending on your needs.
Check this out: https://stackoverflow.com/questions/3484429/profile-and-bashrc-doesnt-work-on-my-mac/3484472#3484472
Related
I followed instructions on this page to change the profile of the Mac terminal when I'm running SSH. The short explanation is that it puts a wrapper script in /usr/local/bin that changes the colour then calls /usr/bin/ssh. When I call this script with the full path it works perfectly, but when I call 'ssh', it appears to use the regular application without the wrapper script.
When I call 'which ssh', the result is '/usr/local/bin/ssh'. My PATH variable is '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin', which looks fine for me. The wrapper script has executable permissions ('-rwxr-xr-x ').
What am I missing? Why would the regular ssh be called rather than than the wrapper script, given the 'which' command points to the one that I want?
You forgot to clear bash's program location cache.
hash -d ssh
I'm trying to write (what I thought would be) a simple zsh script to set up my development environment. The problem I'm running into is that once I get to part of my process, that tab in the shell is devoted only to the last process when I need it to continue running other commands.
More explicitly, I need to run:
lein ring server-headless
then open a new tab, and run
cd ../
cd my_directory/
nodemon
I'm sure this has a simple solution/I should have been a better-Googler, I'm just new to this and didn't know how to word my problem.
Instead of trying this with bash/zsh/etc. I would recommend using Tmux instead :)
Take a look at Tmuxinator for this stuff: https://github.com/aziz/tmuxinator
If you don't want to use tmuxinator, with a few lines of shell code you can still make tmux do this stuff.
I want to create my own personal logfile that logs not only when I log in and out, but also when I lock/unlock my screen. Kindof like /var/log/wtmp on steroids.
To do this, I decided to run a script when I log into Ubuntu that runs in the background until I quit. My plan to do this is to add the script to .bashrc, using ./startlogging.sh & and in the script I will use trap to catch signals. That's great, except .bashrc gets run every time I open a new terminal, which is not what I want for the logger.
Is there a way to tell in Bash that the current login is a gnome login? Alternatively, is there some sort of .gnomerc I can use to run my script?
Edit: Here is my script:
Edit 2: Removed the script, since it's not related to the question. I will repost my other question, rather than repurpose this one.
Are you looking for a way to detect what type of terminal it is?
Try:
echo $TERM
From Wikipedia:
TERM (Unix-like) - specifies the type of computer terminal or terminal
emulator being used (e.g., vt100 or dumb).
See also: List of Terminal Emulators
for bash use : ~/.bash_logout
that will get executed when you logout, which sounds like what you are trying to do.
Well, for just bash, what you want are .bash_login/.bash_logout in your home directory (rather than .bashrc) These are run whenever a LOGIN shell starts/finishes, which happens any time you log in to a shell (on a tty or console, or via ssh or other network login). These are NOT run for bash processes created to run in terminal windows that you create (as those are not login shells) so won't get run any time you open a new terminal.
The problem is that if you log in with some mechanism that does not involve a terminal (such as gdm running on the console to start a gnome or kde or unity session), then there's no login shell so .bash_login/logout never get run. For that case, the easiest is probably to put something in your .xsessionrc, which will get run every time you start an X session (which happens for any of those GUI environments, regardless of which one you run). Unfortunately, there's no standard script that runs when an X session finishes.
Hey guys, I run LinuxMint and I have some scripts which I want to run without terminal, can you tell me how?
You need to:
Put as the first line of your ruby script the following shebang line (so bash knows what program to use to run this file)
#!/usr/bin/env ruby
Make your ruby file executable. In a console you can do this:
chmod 700 my_ruby_file.rb
Test that your ruby file is now executable. In a console write:
./my_ruby_file.rb
Notice that we are no longer calling "ruby my_ruby_file.rb", but instead just call the file directly "./my_ruby_file.rb"
If your ruby program executed normally, then everything is going well. If it does not execute and shows you an error, then something is not well done from the previous steps (and post your error)
In your desktop, create an application link, and point it to the my_ruby_file.rb
Once you have the application icon created and shown in your desktop, you can doble-clickit and it will run your application.
Tell us how it went- cheers
I have a little program that I want to make open automatically when my mac is started up.
Because this program accepts command line arguments, its not as simple as just going to System Prefs/Accounts/Login items and adding it there...
From google, I read that I can create a .profile file in my user's home folder, and that will execute whatever I put in it... So I have a .profile page in ~ like this:
-rw-r--r--# 1 matt staff 27 27 Sep 13:36 .profile
That contains this...
/Applications/mousefix 3.5
But it doesn't execute on startup! If I enter "/Applications/mousefix 3.5" manually into the terminal, it does work.
Any ideas?
From here and into the future, look into launchd for what you want to do. All other methods have been deprecated or are now unsupported. This is probably a bit more heavy-weight than what you want, though.
It could also be a problem with your version of the bash shell not correctly executing your .profile. Try putting the command into .bashrc in your home directory, and see if that helps.
You can use Lingon to help construct a plist file for launchd.
The most general way of launching things on startup on MacOS is using launchd. You can create a plist file to tell it to launch your program on startup, which can include arguments.
You can use Applescript which can run terminal commands, then have that applescript launched at startup.
The .profile and .bash_profile only come into play when you open a new shell (ie. opening Terminal or entering through SSH). Also, I believe if bash detects .bash_profile it won't look for .profile
If you want it start upon login, I would look at the other suggestions about launchd
You could always write a wrapper script that runs it with the arguments you want
Thanks all. The launchd solution is pretty cool, yes its heavyweight for such a simple thing, but its good to know, and as a developer I'm happy to tinker about :)