Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sk3pt1c

macrumors 6502a
Original poster
Nov 29, 2005
918
6
a simulacrum
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
 

kpua

macrumors 6502
Jul 25, 2006
294
0
I highly doubt AppleScript is powerful enough to do this. I would take a look at OmniDazzle though.
 

sk3pt1c

macrumors 6502a
Original poster
Nov 29, 2005
918
6
a simulacrum
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...
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
robbieduncan said:
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.

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
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
Sayer said:
Okay this version will work (my cursor is giant size at the moment):

snip

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.
 

Lixivial

macrumors 6502a
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.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
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
 

thuldai

macrumors newbie
Sep 5, 2006
2
0
NYC, USA
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
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
thuldai said:
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

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.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
whooleytoo said:
(The obligatory..) of course, if we had a resolution independent, this wouldn't even be necessary.. ;)

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.