Running terminal app, at start without the terminal

Posted:
in Genius Bar edited January 2014
I'm running the distributed.net project. You can use a wrapper or run directly from the command line in Terminal. When launched in the CLI, if you quit it will continue working in the background. I'd like to go around the Terminal and have the client start when I log it or even turn on the computer. Is there a specifiy place or a simple script. I want this transparent. No AppleScript "run terminal; do dnetc"



Thanks a lot



And I tried using Login Items and that didn't appear to work.

Comments

  • Reply 1 of 5
    Quote:

    Originally posted by macserverX

    I'm running the distributed.net project. You can use a wrapper or run directly from the command line in Terminal. When launched in the CLI, if you quit it will continue working in the background. I'd like to go around the Terminal and have the client start when I log it or even turn on the computer. Is there a specifiy place or a simple script. I want this transparent. No AppleScript "run terminal; do dnetc"



    Thanks a lot



    And I tried using Login Items and that didn't appear to work.




    Have you tried launchng in single-user mode? Reboot and hold down the command key + the 'S' key. I think that's it. If not just hold down the 'S' key on boot.



    HTH.
  • Reply 2 of 5
    gargoylegargoyle Posts: 660member
    *** Warning ***



    This has been hacked together from my VERY BASIC knowledge of C and cocoa development.



    If some nice programmer knows a better way to do this, perhaps with some proper exit method let me know.



    *** /Warning ***



    1.) Create a new PB cocoa application project.

    2.) Remove the tick boxes from next to MainMenu.nib so that it does not get compiled or added to the finished app.

    3.) Edit main.m to read...

    Code:



    //

    // main.m

    // loginShellScript

    //

    // Created by Paul Court on Wed Aug 13 2003.

    // Copyright (c) 2003 __MyCompanyName__. All rights reserved.

    //



    #import <Cocoa/Cocoa.h>



    int main(int argc, const char *argv[])

    {

    // return NSApplicationMain(argc, argv);



    system("~/.loginScripts");

    return true;

    }







    4.) Build the project

    5.) Copy the application from the build folder to somewhere nicer, like Applications/Utilities

    6.) Add it to login items.

    7.) Create a .loginScripts file in your home folder.

    mine has this in it at the mo

    Code:



    /usr/bin/nice -n +20 /System/Library/Frameworks/

    ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/

    MacOS/ScreenSaverEngine -background &







    (Thats all one line in the real file)



    8.) give the file execute permissions (chmod 744 ~/.loginScripts)



    Edit:

    Skip steps 1 - 4 and use my app
  • Reply 3 of 5
    thuh freakthuh freak Posts: 2,664member
    An alternative to Gargoyle's idea is to run it on the computer's startup, instead of on login. If you only need it to run once per boot, then this way might be better.



    On startup, macosx will automatically run several scripts inside the folder /System/Library/StartupItems/. In order to make a script of your own start automatically on startup, you have to create a folder in that folder. Name it something relevant, like the name of your script. Now, put your script inside, and make sure it has the exact same name as its folder (example, I create a folder /System/Library/StartupItems/myScript, my script inside that folder is named myScript). Make sure the script has execute permissions. There is another file you have to put inside that folder named StartupParameters.plist. It is fairly easy to figure out just what to put in that file, but here's an example anyway:

    Quote:

    {

    Description = "A description of my script.";

    Provides = ( "myScript" );

    Requires = ( "Network", "Apache" )

    OrderPreference = "Late"

    Messages = {

    start = "My script is starting up";

    stop = "My script is shutting down";

    };

    }



    `Description' is kind of obvious. `Provides', from those I've seen, is always the name of the folder/script. `Requires' is a comma separated list of quoted other scripts that yours requires. If your script does networking or anything on the internet, then you'll require `Network'. Look through /System/Library/StartupItems/ to see if your script will require any of those (the quoted names for `Requires', have to be folder names from /.../StartupItems/). `OrderPreference' can be "Late", "None", "First", "Early", and theres probably a few more. I think this has higher preference than `Requires', so I always do "Late". I'm not sure about the last one, `Messages', and if anything else is relevant aside from 'start' and 'stop'. You can see these messages on startup. Also, if your script is sh, bash, or compatible/similar, and sources '/etc/rc.common', then you can call 'ConsoleMessage' with a string as an argument; the string will show up in the same way the 'start' and 'stop' strings show up. Now, save that file inside your folder inside /System/Library/StartupItems/ and restart your computer. If you doubt that your script is working, put a noticeable delay in the beginning of it (like 'sleep 30;'), then when you restart, you should notice your 'My script is starting'.
  • Reply 4 of 5
    Thanks guys, but I have no idea how to write the scripts you are talking about. I looked at the other startup item scripts and they're far more complicated that, I think this should be.



    The distributed client has an absolute path of "/Applications/dnetc/dnetc" So if someone could write a simple script with that. If it's commented I should hopefully get something out of it.
  • Reply 5 of 5
    thuh freakthuh freak Posts: 2,664member
    Quote:

    Originally posted by macserverX

    Thanks guys, but I have no idea how to write the scripts you are talking about. I looked at the other startup item scripts and they're far more complicated that, I think this should be.



    The distributed client has an absolute path of "/Applications/dnetc/dnetc" So if someone could write a simple script with that. If it's commented I should hopefully get something out of it.




    #!/bin/sh

    # This is a sh-script

    #

    # One assumption I'm making is that dnetc is not a cocoa app, so that

    # the path you mentioned is directly to the executable.

    #

    exec /Applications/dnetc/dnetc

    # (end of script)



    If all you are doing is running the program, and absolutely nothing else, it's probably better to instead insert the program where you would've put the script. Like, with the startup-items, make a symbolic link from /System/Library/StartupItems/scriptName/scriptName to /Applications/dnetc/dnetc (sudo ln -s /System/Library/StartupItems/scriptName/scriptName /Applications/dnetc/dnetc). But copying that very short script I wrote above will also accomplish your task.
Sign In or Register to comment.