(applescript) is there a "vardump" command?

Discussion in 'Mac Programming' started by vrillusions, Jan 26, 2011.

  1. vrillusions, Jan 26, 2011
    Last edited: Jan 26, 2011

    vrillusions macrumors regular

    vrillusions

    Joined:
    Jul 8, 2007
    Location:
    Cleveland, Ohio, US
    #1
    In other languages like python and php you can get a dump of every action available on an object. Like var_dump($_POST) in php or dir(os) in python. Is there something similar in applescript? What I'm trying to do is set the mouse sensitivity since I use the mighty mouse for day to day but a usb mouse for gaming and the sensitivities are really different. This is what I have so far:

    Code:
    tell application "System Preferences"
    	activate
    	set the current pane to pane id "com.apple.preference.mouse"
    end tell
    Which will open up the mouse preferences. Now I need a way to set the "tracking" slider to a certain value, probably 0.5 if I want it in the middle. How do I inspect the current pane to get a list of what values I can change and optionally what range they support?

    *edit
    Got a little closer. I think I need to fill in the blank for the statement: 'get the name of every ??? of pane id "com.apple.preference.mouse"' that would give me all the names and I can figure out which is for the tracking slider
     
  2. vrillusions thread starter macrumors regular

    vrillusions

    Joined:
    Jul 8, 2007
    Location:
    Cleveland, Ohio, US
    #2
    So I finally figured it out. There is no vardump type command that I could find but you can kinda do it with UIElementInspector (google it, it's a sample code project from apple). that will at least give you a name if it exists. But ultimately I needed to use System Events and UI scripting. But I found out how to determine the names of sliders that the ui element inspector doesn't give. Here's the working code:

    Code:
    set tracking to 9
    
    tell application "System Preferences"
    	activate
    	set current pane to pane id "com.apple.preference.mouse"
    end tell
    
    -- need a delay before UI Scripting
    delay 1
    
    tell application "System Events"
    	tell process "System Preferences"
    		-- This returns the name of "slider 1" used below
    		-- get name of slider 1 of window "Mouse"
    		set value of slider "Tracking" of window "Mouse" to tracking
    	end tell
    end tell
    
    tell application "System Preferences" to quit
     

Share This Page