Magento add position 999 when assign product to category

You need to create a new module.. Its working fine. I tested it.

Let's call it Product_Position.

app/etc/modules/Product_Position.xml - the declaration file

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Product_Position>
            <active>true</active>
            <codePool>local</codePool>
        </Product_Position>
    </modules>
</config>

app/code/local/Product/Position/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <Product_Position>
            <version>0.1.0</version>
        </Product_Position>
    </modules>
    <global>
        <models>
            <position>
                <class>Product_Position_Model</class>
            </position>
        </models>       
    </global>
    <adminhtml>
        <events>
            <catalog_product_save_after><!-- observe the event -->
                <observers>
                    <product_position>
                        <type>singleton</type>
                        <class>Product_Position_Model_Observer</class>
                        <method>setPosition</method>
                    </product_position>
                </observers>
            </catalog_product_save_after>
        </events>
    </adminhtml>
</config>

app/code/local/Product/Position/Model/Observer.php - the observe class

<?php

class Product_Position_Model_Observer extends Mage_Core_Model_Abstract
{
    public function setPosition($observer) {
        $product = $observer->getEvent()->getProduct();
        $id = $product->getId();
        $resource = Mage::getSingleton('core/resource'); //get an instance of the core resource
        $connection = $resource->getConnection('core_write');
        $tableName = $resource->getTableName('catalog/category_product');
        $sql = "UPDATE {$tableName} SET `position` = 999 WHERE `product_id` = {$id}"; //set the position for the product in all the categories.
        $connection->query($sql);
    } 
}