Can I auto run a script when editor launches or a project finishes loading?

Basicly I have a function that needs to run for my project every time I start the editor. It is too much work to haveing to manually select a menu command every time.

static public class StartUp { static public void StartUpTask(){ ...; } }

I know that I can use a command line to launch the editor with "-executeMethod Startup.StartUpTask" but this too is annyoning to launch that particular project via a shortcut everytime as well!

Is there anywhere I can hook Startup.StartUpTask(); To run reguadless of the scene or having to select a menu command? Is there some editor class I can derive from that will post notifications?

(All code in C#)

This works great ... save this as Autorun.cs in your Editor folder. The InitializeOnLoad attribute is the special sauce that makes it work. (I've deprecated my previous answer with the custom editor for Transform, this is a much better approach.)

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class Autorun
{
    static Autorun()
    {
        Debug.Log("Autorun!");
    }
}

If you want the scene to be fully loaded before your startup operation, for example to be able to use Object.FindObjectsOfType, you can defer your logic until the first editor update, like this:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class Autorun
{
    static Autorun()
    {
        EditorApplication.update += RunOnce;
    }

    static void RunOnce()
    {
        Debug.Log("RunOnce!");
        EditorApplication.update -= RunOnce;
    }
}

Hey guys,
I have a little problem which is similar to this one.
I did such an autorun class to view a menu in the scene view.
My main Problem is, not every line of the code is executed at the beginning. If I open up a new scene then every part of the code which has an if statement it is not executed.
something like:

//Create Skybox if there is none
Debug.Log("Look if there is a skybox");
 if (RenderSettings.skybox == null)
    {
        Debug.Log("There is no skybox, I ll create it");
        RenderSettings.skybox = skybox;
    }

So the first Debug.log is shown and there is really no skybox but the second one isnt shown and it will not create a skybox until i edit something in the code, save that change and go back to unity. Then the script is called again and the skybox will be created

InitializeOnLoad is not perfect, it will make editor script rerun on each “enter Play mode” or “exit Play mode”, it will cause “Enter Play Mode” or “Exit Play Mode” very slow, so I use following if (!EditorApplication.isPlayingOrWillChangePlaymode)to ignore this case and make script only run on
unity editor startup

using UnityEditor;

namespace EditorScript.Ro.Startup
{
    [InitializeOnLoad]
    public class StartupMain
    {
        static StartupMain()
        {
            // InitializeOnLoad will cause run each InitializeOnLoad on enter or exit play mode, it will cause unity editor slow, so ignore this case
            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                new AutoSave();
                new ChangeUnityEditorWindowTitle();
                new DisableAutoRefresh();
                new NotifyMoveLibScriptsToStandardAssets();
                new ReceiveRiderCmd();
            }
        }
    }
}

Look into this: http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode.html

Maybe you can make a Startup or Awake function with that.