+2  A: 

Two things here - firstly, you need to have checked the "Enable access for assistive devices" in System Preferences / Universal Access / Mouse & Trackpad. Obviously you've already done this, otherwise the script wouldn't get to where it is without already failing, but it's an important step for anyone else trying to get this working.

Secondly, the problem with the line you were receiving the error on was that you weren't telling the AppleScript where to find the slider you were wanting to change the value of. By changing the line to the following, the script started working:

set value of slider "Tracking Speed" of window "Mouse" to trackingValue

Note that as well as naming the window to be used by the AppleScript I have also named the slider to be used as well. Whilst running Snow Leopard and using "slider 1", the second slider in the window "Scrolling Speed" was being altered. So, by using the name of the slider rather than its number we bypass any possible indexing issues. As for working out the name of the slider? I simply tried using the value of the label that went with it, which worked in this instance. Your mileage may vary, of course.

Thus, the final script becomes:

set trackingValue to 5

--Open and activate System Preferences
tell application "System Preferences" to activate

--Attempt to change settings using System Events
tell application "System Events"
    tell process "System Preferences"
     try
      --Open the "Keyboard & Mouse" pane
      click menu item "Mouse" of menu "View" of menu bar 1
      delay 2
      set value of slider "Tracking Speed" of window "Mouse" to trackingValue
      --end tell
     on error theError
      --An error occured
      display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
     end try
    end tell
end tell
NeilCrosby
I had to make on change...set value of slider "Tracking" of window "Mouse" to trackingValue...but otherwise your script did the trick. Thanks
Jason
Script worked for me without any edits. Nicely done and nicely explained!
mikeh
it also worked for me when I used: set value of slider "Tracking" of window "Mouse" to trackingValue. A very good example.. Thanx :) One question - can you tell us similar script to set: action of right mouse pop-up button to secondary button action?
Miraaj