Toggle Bluetooth AppleScript not Working in Yosemite Prior to upgrading to Yosemite, I used Keyboard Maestro to invoke this Applescript with a shortcut:

tell application "System Preferences"
    reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
    click button 6 of window 1
end tell
quit application "System Preferences"


It behaved just as expected, toggling bluetooth whenever I pressed my shortcut. 

It's no longer working with Yosemite though, I'm sure it has something do with Apple changing the System Preferences pane or the order of icons, but I'm not sure what to change. The Keyboard Maestro shortcut is invoking the file, because I hear the sound I had assigned to it, so it's definitely something with the script.

Here's what I'm getting under "Replies" when I run this in Apple's Script Editor:

tell application "System Preferences"
    reveal pane "com.apple.preferences.Bluetooth"
        --&gt; missing value
end tell
tell application "System Events"
    click button 6 of window 1 of process "System Preferences"
        --&gt; button 6 of window "Bluetooth" of application process "System Preferences"
end tell
tell application "Script Editor"
    quit
end tell


Updates:

It's definitely not the pane that's causing the problem. To debug, I changed the code to:

tell application "System Preferences"
    set current pane to pane id "com.apple.preferences.bluetooth"
end tell


And it correctly opens the Bluetooth pane. Now all that's left is to figure what kind of action I want to run on this pane:



Update on solutions: Thanks fartheraway! Both of markhunte's and fartheraway's solutions worked for me, but I chose the latter because it was more similar to my code. I guess you can't choose two "best" answers. I wish there'd be a solution to make it work without bringing up the preferences pane (visually) like my script did with Mavericks, but these two should be good enough.
Simple toggle on or off that does not need to check state first.

property thePane : "com.apple.preferences.bluetooth"

tell application "System Preferences"
    activate
    set the current pane to pane id thePane
    --delay 1
end tell

tell application "System Events"
    tell application process "System Preferences"
        try
            click button "Turn Bluetooth Off" of window "Bluetooth"
        on error
            click button "Turn Bluetooth On" of window "Bluetooth"
        end try
    end tell
end tell

tell application "System Preferences" to quit