cursor enlarging applescript?

Discussion in 'Mac Programming' started by sk3pt1c, Aug 18, 2006.

  1. macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #1
    ok,i just got the new wireless mighty mouse.
    i had a microsoft mouse before just to have the right click,
    but since the new mighty mouse has right click to i decided to go all apple.
    what i want is this
    the microsoft mouse had a proper ****ty range
    since the mighty mouse is bluetooth,i'd like to use it from afar to play music and stuff when i'm in bed and so on
    but if i'm that far i can't really see the cursor really well
    so i was thinking
    could i have an applescript assigned to one of the side buttons that enlarges the cursor when i click it so i can use it from the bed and returns it to its normal size when i click it again?
    i've never even looked at applescript before so please be gentle :)
    thanks for everyone's time
    john
     
  2. macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    I highly doubt AppleScript is powerful enough to do this. I would take a look at OmniDazzle though.
     
  3. thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #3
    basically i want an applescript to access the Universal Access settings from the Settings and change the size of the cursor,and then assign that to a button on my mouse
    no way i can do that with applescript then?
    omnidazzle looks cool (and the flashlight feature would do the job i guess) but i'd rather not download something to do this, don't like having lots of small applets running...
     
  4. thread starter macrumors 6502a

    sk3pt1c

    Joined:
    Nov 29, 2005
    Location:
    a simulacrum
    #4
    so i'm guessing by the lack of response that it's not possible to do with applescript
    right?
    anyone?
     
  5. macrumors newbie

    Joined:
    Sep 3, 2006
    #5
    At first glance it doesn't seem possible, I'm looking into this, too. I agree with you about not using a separate utility for this.

    ~ Christefano
    http://parahuman.org/contact/
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Applescript is basically for integrating and controlling other applications, providing custom links between them. It is not for system level modification. Unless the system can already do this at some level Applescript won't be able to do it.
     
  7. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #7
    Robbie's half right. He's right about what AppleScript is for, but enlarging the cursor is definitely something the system can already do. What you need to do is write an AppleScript that uses GUI scripting to directly modify the setting in System Preferences. I have a couple AppleScripts that automatically change the mouse tracking speed using GUI scripting.

    This should get you started. It has a problem, but I have to leave right now, so no time to track it down. If System Preferences is already open, it works fine. However, for some reason, if the script itself has to open System Preferences, it fails. I'm not sure why, but hopefully I or someone else can figure it out later.

    Code:
    --(*cursor size is the desired cursor size
    --It should be an integer from 1 to 4*)
    set cursorSize to 4
    
    --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 "Universal Access" pane
    			click menu item "Universal Access" of menu "View" of menu bar 1
    			
    			--Now set the tracking value. The delays prevent actions being sent before previous ones have been completed
    			delay 2
    			tell tab group of window "Universal Access"
    				click radio button "Mouse"
    				delay 2
    				set value of slider 3 to cursorSize
    			end tell
    		on error theError
    			--An error occured
    			display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
    		end try
    	end tell
    end tell
    delay 1
    tell application "System Preferences" to quit
    
     
  8. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #8
    Okay this version will work (my cursor is giant size at the moment):

    Code:
    --(*cursor size is the desired cursor size
    --It should be an integer from 1 to 4*)
    set cursorSize to 4
    
    --Open and activate System Preferences
    tell application "System Preferences" to activate
    
    --Attempt to change settings using System Events
    
    tell application "System Events"
    	--	try
    	--		activate
    	--Open the "Universal Access" pane
    	click menu item "Universal Access" of menu "View" of menu bar 1 of process "System Preferences"
    	
    	--Now set the tracking value. The delays prevent actions being sent before previous ones have been completed
    	delay 2
    	tell tab group of window "Universal Access" of process "System Preferences"
    		click radio button "Mouse"
    		delay 2
    		set value of slider 3 to cursorSize
    	end tell
    	(*	on error theError
    			--An error occured
    			display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
    		end try*)
    end tell
    delay 1
    tell application "System Preferences" to quit
     
  9. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #9
    FYI you can make a specific Preferences item open in System Preferences by using:

    Code:
    tell application "System Preferences"
    	activate
    	set current pane to pane "com.apple.preferences.universalaccess"
    end tell
    Just use the appropriate bundle ID for the Preference pane.
     
  10. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #10
    Actually this has the same problem as my original script at least on my machine. If System Preferences isn't already open when you run the script, it throws up an error. I don't quite understand why, because I have a very similar script (upon which this one is based) that changes mouse tracking settings and it works fine all the time.
     
  11. macrumors 6502a

    Lixivial

    Joined:
    Jan 13, 2005
    Location:
    Between cats, dogs and wanderlust.
    #11
    Well, there is one small bug in the script, which isn't a bug and doesn't necessarily mean much. But on different machines the "Mouse" tab is titled different things -- on laptops it's titled "Mouse & Trackpad".

    As for the error that's thrown when system preferences is closed, try simply throwing a delay before the "click menu item" event, because the System Preferences takes a moment or two to initialize all the prefpanes.

    Code:
    tell application "System Events"
    	tell process "System Preferences"
    		try
    			delay 1
    			--Open the "Universal Access" pane
    			click menu item "Universal Access" of menu "View" of menu bar 1
    That seemed to fix the bug which threw the error when System Preferences was closed.
     
  12. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #12
    Thanks Lixivial, that did the trick. I've changed it so it automatically toggles between a smaller size and the size set by changing the value of cursorSize. Paste it into Script Editor (in your Utilities folder), save it as an application, then set that application as the action for the Mighty Mouse button you want to use. You also need to turn on GUI Scripting using AppleScript Utility (found in /Applications/AppleScript) Here's the script for a desktop Mac:
    Code:
    --(*cursor size is the desired large cursor size
    --It should be an integer from 1 to 4*)
    set cursorSize to 4
    
    --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
    			delay 1
    			--Open the "Universal Access" pane
    			click menu item "Universal Access" of menu "View" of menu bar 1
    			
    			--Now set the tracking value. The delays prevent actions being sent before previous ones have been completed
    			delay 2
    			tell tab group of window "Universal Access"
    				click radio button "Mouse"
    				delay 2
    				set currentCursorSize to value of slider 3
    				if (currentCursorSize is less than cursorSize) then
    					set value of slider 3 to cursorSize
    				else
    					set value of slider 3 to 1
    				end if
    			end tell
    		on error theError
    			--An error occured
    			display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
    		end try
    	end tell
    end tell
    delay 1
    tell application "System Preferences" to quit
    and for a notebook Mac (untested because my PowerBook isn't handy ATM):
    Code:
    --(*cursor size is the desired large cursor size
    --It should be an integer from 1 to 4*)
    set cursorSize to 4
    
    --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
    			delay 1
    			--Open the "Universal Access" pane
    			click menu item "Universal Access" of menu "View" of menu bar 1
    			
    			--Now set the tracking value. The delays prevent actions being sent before previous ones have been completed
    			delay 2
    			tell tab group of window "Universal Access"
    				click radio button "Mouse & Trackpad"
    				delay 2
    				set currentCursorSize to value of slider 3
    				if (currentCursorSize is less than cursorSize) then
    					set value of slider 3 to cursorSize
    				else
    					set value of slider 3 to 1
    				end if
    			end tell
    		on error theError
    			--An error occured
    			display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
    		end try
    	end tell
    end tell
    delay 1
    tell application "System Preferences" to quit
     
  13. macrumors newbie

    Joined:
    Sep 5, 2006
    Location:
    NYC, USA
    #13
    Thanks for that hint! Makes it possible for me to program my very first AppleScript to do something similar (to quickly turn the MightyMouse right-click on or off; some users here love it, some hate it).

    One question though, and I apologize for taking this a bit off-topic: How can I find out the names of GUI elements? Where do you have terms like 'radio button "Mouse"' or 'slider 3' from? I don't know how to address the setting for the right mouse button to change it.

    Thanks for any help.

    ThulDai
     
  14. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #14
    There is a little utility called UIElementInspector that you can download to help with that. This page has a link to it, and also tells a little more about GUI Scripting. To be honest though, I still find that pretty confusing to use, and have to use sort of a combination of trial and error and intuition based on experience. There is an alternative. It's called Prefab UI Browser, and it makes it really easy to write AppleScripts that script the GUI. I don't own it (it's $55), but if you're going to do a lot of GUI scripting, it's very useful. There is a trial available of course.
     
  15. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #15
    (The obligatory..) of course, if we had a resolution independent, this wouldn't even be necessary.. ;)
     
  16. macrumors 68040

    mduser63

    Joined:
    Nov 9, 2004
    Location:
    Salt Lake City, UT
    #16
    Not really. It would just mean that the cursor could be scaled without a degradation in quality. By that I mean, it wouldn't get all pixellated. There's nothing guaranteeing you wouldn't need an AppleScript to automatically change the scaling factor. That would only cease to be necessary if Apple specifically implemented the ability to map the change in scaling factor to one of the mouse buttons, which seems unlikely to happen.
     

Share This Page