![]() |
Launching script on login
Ok, so I'm trying to set a script to run every time I log in..
My script looks like: #! /bin/sh <some unix commands> I've named it script.command and set it as executable (chmod +x). I can run it from terminal as ./script.command So far so good... What I want to do is set this to run on Login. I've tried to do this through System Preferences >Accounts > Login Items and adding it as a Login Item, but on login Finder loads it in Smultron (my default text editor) instead of exectuing it as a script. How can I make it run as a script? Sounds like ti should be easy bit I've spent a long time trying to make this work! |
I think you'll need to wrap this script in some way to make it a double-clickable application (e.g. wrap it in AppleScript) in order to run it as a Login Item.
I.e. I think Login Items need to be applications. An alternative might be to install your script as a "login hook" - google for this or look for discussion on these forums or the main macosxhints site. |
I've always used Launcher to run login scripts. After Launcher is installed, just use Get Info to set your shell script to "Open With" Launcher, then add the script to your Login Items. Note that this assumes your script is non-interactive, ie. it doesn't need to open a terminal window.
I'm not sure of Launcher's "Universal Binary" status at this point either (it's Carbon; can these be Universal?): I've been using it on my G4 for years with no problems whatsoever. |
if you want a shell script to launch at login, just call it from launchd. use a plist like this:
Code:
<?xml version="1.0" encoding="UTF-8"?> |
tw has it right. launchd is built just for this purpose, and it's easy to use. Try Lingon as a graphical editor for the plist.
|
Quote:
|
How often do you expect updates? It was last updated in November, just 2 months ago. And most of all, it works great.
|
oh, I know - didn't mean to be critical. but I'm finding it very limiting. that's intentional (the author is aiming for a novice's tool).
|
Are you sure your problem isn't with launchd and not Lingon? I've been trying to get a script to run at login, but it only runs at startup. If I logout and back in, it doesn't run. Lingon produces essentially the same plist as you have in post #4, so I doubt that it is the problem.
|
Quote:
That is a (Tiger) launchd bug. Have you got 'OnDemand' false? Maybe I'm wrong in this case, but that too will act as you describe. And Leopard fixed it by giving the user their own instance of launchd. In Tiger there was but *one* launchd proc. -HI- |
Yes, I'm running Tiger. It's strange, because Activity Monitor shows launchd as on of my processes. Oh well, I guess I'll go back to using an Applescript run-only application at login.
|
Quote:
Are there more than one launchd procs? |
Yes, there's launchd (1) whose parent is kernel_task(0) and launchd (94) whose parent is launchd (1)
|
Quote:
Code:
tail -c numberofbytes /var/log/secure.logCode:
Jan 10 13:30:43 My-Mac SecurityAgent[2086]: User Authenticated: continue login process |
That might work. I'd have to make the script owned by root or an admin user though, since I have a standard account for daily use.
|
Thanks for all the suggestions guys. I tried tws method (seems most elegant). Unfortuantly it doesn't seem to be executing - I've also tried doing the same thing using lingon, and still no luck.
My script needs to be run as root - is this the problem? I though Startup items ran as root anyway? My script is: Code:
#!/bin/sh |
Bombich has a loginwindow.app that will run scripts at log in and log out. Download it, install it, point the app to your script, give it admin access, done.
www.bombich.com |
Wow, I just found this thread. Took long enough for someone to finally mention loginhook functionality!!
Bombich's Loginwindow Manager will allow you to use a GUI to set both loginhooks and logouthooks -- scripts that the loginwindow process will run, as root, before the user's GUI session actually starts. Now, that may or may not be what you want to do. If you want a script to run after the login -- after the Desktop appears -- the launchd method is great. Alternatively, you can use Platypus to generate a double-clickable app from any shell script and put it in your login items. |
Quote:
:) |
D'oh! LOL!
|
Login Hook, launchd, it just doesn't seem to want to work. :confused:
I'm trying to automatically start Folding@home on login. So far, the only way I've been able to do it is using an Applescript.app and login items. I need a way to execute this line in a Terminal window: /path/to/fah5 -local If I try to execute it from a shell script, it doesn't run. If that shell script is a login hook, it hangs the system! From Applescript I can tell the Terminal to open a new window and execute fah5 in it, but I'd prefer to get a login hook or launchd to work. Any ideas? - Oh, and this is in Tiger. |
I used Lingon to create this LaunchAgent:
Code:
<?xml version="1.0" encoding="UTF-8"?> |
Close! But it doesn't get the -local portion correct. This gets logged repeatedly in the Console:
Quote:
Yes, moving the app seems to work, but since it's no longer running in a Terminal window, I can't be sure. Anyone know of a way to redirect the output of a running process? It appears to be writing these files: /usr/lib/dyld /usr/lib/libSystem.B.dylib /dev/null /dev/console I'm assuming /dev/null would normally be the Terminal window. |
Isn't folding@home an application, or is it strictly a background process?
So, maybe use loginwindow manager with this simple shell script, of course this will be at log in not start up, so you would have to log in. Code:
#!/bin/bash |
Quote:
Code:
<key>StandardOutPath</key> |
Quote:
Quote:
|
Quote:
To fire up an "app" via launchd plist, here is another way (I use): Code:
|
Well, I thought it was working. :(
For some reason, FAH is failing in the middle of work units: I noticed this at the top of the output file: Ignoring argument: -local when I run it from the Terminal, I get: Using local directory for work files Here's a sample error: Code:
[18:39:32] Writing local files |
Quote:
Try writing a script that will launch FAH for you. and then just calling that script from launchd. Have the script export HOME as your users home directory. I know there are provisions for defining the home directory within a launchd plist, but I've not used them so I don't know if this will help. OTOH if you have the plist in ~/Library/LaunchAgents I've got no idea. Does FAH have any way to pass more info to it on launch (--path-to-workspace="")? p.s. do any of you have trouble hitting tab to auto-complete only to realize your in a text editor?...I do this all the time. |
The plist is in ~/Library/LaunchAgents. I tried to do this through a script, but I don't know of another way to run it from a Terminal window without using osacript, in which case I might as well call it from login items.
|
Quote:
|
Won't that cause it to run for each user that logs in? If I give it explicit paths in that case, they couldn't be in a user's home, but if they weren't, then I could end up with multiple instances working on the same data.
Maybe I'll try it between snow shoveling sessions tomorrow. :eek: |
well, the other alternative is to launch it from the root folder, but use the UserName key to make sure it always runs as a particular user (I'm assuming they have that key in Tiger, incidentally - I only have easy access to the Leopard man page). that might mean that you'd want create a separate user dedicated to doing whatever it is this app does...
I checked out the folding@home website, incidentally. you know, on the FAQ page they imply you can just add folding@home to your login items, and it will run just fine. see it here... did you try that way, and if so what was the problem? |
That's the graphical application. I'm using the command line console in this case so that it runs in the background while I use the system. I also run the screen saver, so that gives me two instances at a time. Since I've only got a dual processor system, that's all I want running.
|
Here's the Applescript I was using to start it. I saved it as a run only app and added it to login items, and it works well, except that I can't do anything until after the gui scripting completes. A login hook or launchd wouldn't need the gui portion and it would be quicker too.
Code:
tell application "Terminal" |
well, the Console version has the same instructions (here). my sense is, though, that this opens and runs the command in terminal. let me try downloading it myself and see what happens...
|
Quote:
|
Quote:
I actually wouldn't mind doing this myself, but man is it a CPU hog. does that settle down after a while? |
It's low priority, so it gets out of the way easily, but it will use as much of the cpu as is available. That's what I like about it. I can leave it running all the time, and it won't hog the processor when I need it. When I leave the computer, I start the screen saver, which keeps the other processor busy. That way my system is doing some good while I'm not using it.
|
cool. I will run it then. :)
|
| All times are GMT -5. The time now is 10:16 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.