How can I run this code on startup?

Discussion in 'Mac OS X Lion (10.7)' started by rimmi2002, Mar 24, 2012.

  1. rimmi2002 macrumors member

    Apr 6, 2011
    Hi I wanted to run this code on each startup:
    sudo pmset womp 0

    Can someone please tell me how can I do it? Thanks.
  2. rimmi2002 thread starter macrumors member

    Apr 6, 2011
    K I used sudo nana and the pasted the command in there. Saved the file and gave it the following permissions sudo chmod +x filename.

    I added the file to startup script. It runs the command in terminal now, but asks for my password to execute on each startup. Anyway I can bypass the ask password step on provide the password in the command? Please advise. Do I need to allow different permissions to the file?
  3. haravikk macrumors 65816

    May 1, 2005
    The best way to do it is with launchd, it's not quite as simple as a login or startup item, but by creating it in /Library/LaunchDaemons it can run as root.

    The file you'd want to create would look something like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
    Just create the file in that format under something like:

    This should cause it to run invisibly, and you can use the label of com.pmset to check that it's running in the Console.

    While it's a bit more of a learning curve, I think that launchd is the best way to run anything at start-up, on a specific date (daily, weekly etc.), or for watching out for volume changes (mount) or folder updates. I use it now for all sorts of things, including setting the noatime flag on some volumes, checking if Macports needs updating and so-on.
  4. rimmi2002 thread starter macrumors member

    Apr 6, 2011
    Thanks. I tried this. The files exist in launchdameons, but does nothing. I find not mention of it in the console in all messages section and It does not turn off wake on network, like it suppose to. Is there anything else I can do to make it work?
  5. larkost macrumors 6502a

    Oct 13, 2007
    The most probable problem is that you don't have the permissions right on the file. It should be owned by root, and needs to be readable by root, and not writeable by anyone other than root. The following commands should take care of that:
    sudo chown root:wheel /Library/LaunchDaemons/com.pmset.plist
    sudo chmod 755 /Library/LaunchDaemons/com.pmset.plist
    Note that I am assuming the example path given above (which I would never normall use... it should not be "com.", but something like "personal.pmset.plist"). You can check if it has run with:
    sudo launchctl list | grep 'com.pmset'
    If it has sucessfully run there should be a '-' in the first column, and a '0' in the second. Otherwise you might want to look in the system log.
  6. rimmi2002 thread starter macrumors member

    Apr 6, 2011
    Thanks for the help. I guess it does run, because I got a - and 0 which using the GREP function. How it doesn't do what its suppose to do. Something in my system always enables wake on network on startup. I am not sure what it is...When I uncheck it..its rechecked on startup. So command might be running before the other function that is enabling it on each startup.
  7. rimmi2002 thread starter macrumors member

    Apr 6, 2011
    Just figured it out. The stupid problem was from Logmein...which had wake on LAN enabled. So each time or system start it would enable wake on lan. The script was probably running before Logmein started and thats why it reverted back to pmset womp 1. Thanks for the help!
  8. haravikk macrumors 65816

    May 1, 2005
    Oh, sorry about the permissions trouble, I forget I always use sudo to do anything Launch Daemon related! As for the naming convention, it doesn't really matter what it's called, as long as it's unique, I usually put something like "com.haravikk.<process name>", but it doesn't really matter either way.

    Anyway, glad to here it's working for you!

Share This Page