PDA

View Full Version : cursor enlarging applescript?




sk3pt1c
Aug 18, 2006, 08:57 AM
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
Aug 18, 2006, 09:05 AM
I highly doubt AppleScript is powerful enough to do this. I would take a look at OmniDazzle though.

sk3pt1c
Aug 18, 2006, 09:37 AM
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...

sk3pt1c
Aug 20, 2006, 08:39 AM
so i'm guessing by the lack of response that it's not possible to do with applescript
right?
anyone?

christefano
Sep 3, 2006, 07:23 AM
so i'm guessing by the lack of response that it's not possible to do with applescript
right?
anyone?

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/

robbieduncan
Sep 3, 2006, 07:52 AM
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
Sep 3, 2006, 10:58 AM
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.


--(*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
Sep 3, 2006, 12:07 PM
Okay this version will work (my cursor is giant size at the moment):

--(*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
Sep 3, 2006, 12:10 PM
FYI you can make a specific Preferences item open in System Preferences by using:

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
Sep 3, 2006, 01:26 PM
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
Sep 4, 2006, 04:25 PM
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.

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
Sep 4, 2006, 05:44 PM
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:

--(*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):
--(*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
Sep 5, 2006, 09:16 AM
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
Sep 5, 2006, 09:50 AM
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 (http://www.apple.com/applescript/uiscripting/02.html) 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 (http://www.google.com/url?sa=t&ct=res&cd=1&url=http%3A%2F%2Fwww.prefab.com%2Fuibrowser%2F&ei=vI79RNLzDprkgQPD9pChAw&sig=__JndlIaTean9VmP1D9SZ41u1xoRE=&sig2=baxptp92GmnM2LoBRdOGFA), 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.

whooleytoo
Sep 5, 2006, 02:47 PM
(The obligatory..) of course, if we had a resolution independent, this wouldn't even be necessary.. ;)

mduser63
Sep 5, 2006, 03:19 PM
(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.