Setting the mouse tracking speed via applescript - osx-snow-leopard

I'm trying to get an apple script to set the mouse tracking speed in OS X 10.6, specifically with a new Magic Mouse.
I've found the following:
set trackingValue to 5
--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 "Keyboard & Mouse" pane
click menu item "Mouse" of menu "View" of menu bar 1
delay 2
set value of slider 1 to trackingValue
--end tell
on error theError
--An error occured
display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
end try
end tell
end tell
But it seems to be built for 10.5 as I get an error when trying to 'set value of slider 1 to trackingValue'
2 questions...
How can I get this to work with the 10.6/Magic Mouse combo?
How would I go about getting the name of the slider on the control panel, or any other control for that matter, for use in applescript?

Two things here - firstly, you need to have checked the "Enable access for assistive devices" in System Preferences / Universal Access / Mouse & Trackpad. Obviously you've already done this, otherwise the script wouldn't get to where it is without already failing, but it's an important step for anyone else trying to get this working.
Secondly, the problem with the line you were receiving the error on was that you weren't telling the AppleScript where to find the slider you were wanting to change the value of. By changing the line to the following, the script started working:
set value of slider "Tracking Speed" of window "Mouse" to trackingValue
Note that as well as naming the window to be used by the AppleScript I have also named the slider to be used as well. Whilst running Snow Leopard and using "slider 1", the second slider in the window "Scrolling Speed" was being altered. So, by using the name of the slider rather than its number we bypass any possible indexing issues. As for working out the name of the slider? I simply tried using the value of the label that went with it, which worked in this instance. Your mileage may vary, of course.
Thus, the final script becomes:
set trackingValue to 5
--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 "Keyboard & Mouse" pane
click menu item "Mouse" of menu "View" of menu bar 1
delay 2
set value of slider "Tracking Speed" of window "Mouse" to trackingValue
--end tell
on error theError
--An error occured
display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
end try
end tell
end tell

If you are using Mavericks 10.9 there is an extra tab group you need to consider, this script works:
set trackingValue to 8
--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 "Keyboard & Mouse" pane
click menu item "Mouse" of menu "View" of menu bar 1
delay 2
tell tab group 1 of window "Mouse"
set value of slider "Tracking" to trackingValue
end tell
--end tell
on error theError
--An error occured
display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
end try
end tell
end tell

Jason's suggestion seems not working in 10.8. I tried to replace "Tracking Speed" with "Tracking", the value was not set correspondently.
Wonder they've changed the name of the slider or not.

The script still functions as intended with OS X Lion 10.7. One small change I added after setting the Tracking Speed value is:
set value of slider "Tracking Speed" of window "Mouse" to trackingValue
tell application "System Preferences" to quit
--end tell
This closes System Preferences so I'm not left looking at a menu pane and can get back to my work with my mouse's now speedier tracking.

This works on my Sierra OS X machine. If you get an error, you may have to slightly lengthen one or both of the script delays to better match the speed your machine.
set trackingValue to 8
--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 "Mouse" pane
click menu item "Mouse" of menu "View" of menu bar 1
delay 0.5
tell window "Mouse"
set value of slider "Tracking speed" to trackingValue
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
tell application "System Preferences" to quit

For some reason those scripts were not working in OS X 10.10. Needed a little tweaking but now it works.
set trackingValue to 9
--Open and activate System Preferences
tell application "System Preferences" to activate
tell application "System Preferences"
reveal pane "com.apple.preference.mouse"
end tell
--Attempt to change settings using System Events
tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window "Mouse"
set value of slider "Tracking" to trackingValue
end tell
end tell
end tell
tell application "System Preferences" to quit
Enjoy.

Related

WinForms - Can't add picture to picturebox

I pretty much just started using Windows forms and I'm trying to add a picture to a picture box. First I tried the most obvious way, that is - clicking on the little arrow in the top right corner of a picturebox and clicking "choose image" in the small dialog box, but no matter what I do, the "choose image" button does utterly nothing. I know it should open some dialog box where I could choose my picture, but litterally nothing happens, not even an error message pops up.
Next I tried importing the picture through the properties of the picturebox, but after clicking on the three dots next to the image property an error message pops up, saying "value cannot be NULL, Name o parameter: docData".
I tried following this answer (How to attach a resource (an image for example) with the exe file?) and going to the properties of my project and then to the resources tab, but I have this tab completely empty, saying just that my project does not contain any default resources and a "click to create them" button. However when I click it, another error message appears saying "system cannot find the file. Exception based on value HRESULT:0x80070002"
I guess the problem must be somewhere in my resources file (which might be missing or whatever), but I have a default .resx file there that I haven't touched since the creation of this project which I had thought should be fine.
Afterall I pretty much just started with WinForms and I don't have much clue what's going on and this is quite a significant setback for me. I would be grateful for any help.

GTK+3 disable the close icon present in a window (c program)

I'm developing a GUI in Linux (Ubuntu 16.04 - WM: Gnome) using GTK+3 and the graphic library cairo.
After clicked on a push button (Plot), using the instruction of cairo I draw a red square on a new top window where I put a GtkDrawingArea.
In this window I also put a push button (Cancel) that clicked, hide the window. In this way, if I re-push "Plot", the red square reappear.
The issue is the "x" icon present in the top bar of the window.
If (no me) a user push this x, the window disapper and if he re-push the "Plot" an error is reported.
The question is: it is possible avoid this possible cause of error?
(remove this "x" from the top bar of the window or in some way disable its functionality).
I tryed to find alone a solution and the possibility found are:
1 - Remove from the window the property of "decorated".
The top bar disapper (so also the x) but is not possible move the window on the screen
2 - Using the function gtk_window_set_deletable(window, FALSE) (used before to show the window), but the x is always there and pushing it the window is destroyed.
If you think that can be useful, I can report the code.
I'm waiting your suggestion.
Edit:
Now we know what you want to achieve: display a separate window but avoid destroying it so you can display it again. You already have in the "Cancel" button of your secondary window the logic to hide it.
The cleanest solution is to just do the same: when the user tries to close the secondary window, hide it instead. This way the user is not frustrated of seeing something that apparently doesn't work as expected. Hidden or closed, it's different for you but it's the same for the user.
So you just need to connect to the delete-event of that secondary window, and hide it. There's even no need to create a specific callback for that, GTK+ provides it for you: you just need to connect the delete-event to gtk_widget_hide_on_delete. To display the window again, just call gtk_widget_show_all on it.
Original answer:
I realize the plot
"realize" is a term that has a defined meaning in GTK+. Don't use it out of context, and try to use an alternate term if you're not talking about widget realization.
What I would like is to remove this "x" from the top bar of the window
or in some way disable its functionality.
Do you understand this is ultra annoying for a user and defeats a unified user experience? Would you like to use applications that do random different things?
Anyway, one way of disabling the closing button is to connect to the delete-event and return TRUE there to stop the propagation of the event. The button will still be there but do nothing, so you will have to kill the app to exit it.
To make the button disappear, gtk_window_set_deletable will ask the Window Manager to do that, but we'd need some code to know what's wrong with your attempt.

extjs desktop - how to hide a window when it is created?

I am storing values of extjs desktop window in a database.
Case:
When user minimized a window and logs out,
the window should stay minimized when he logs in again.
Now on logon the before minimized window pops up
The values are all there! But I cant find the property to set...
I tried hidden:true, but no effect.
I was looking for a property to set when creating the window for extjs-desktop. But a superior function is invoking creation, takes window as response and does "win.show()". At this point i am checking the "minimized" value delivered by AJAX.

In forms application, is there any Alternative to MsgBox?

I like how MsgBox stops all further processing until it's clicked but I don't like how it pops that little msgbox in the middle of the screen. Is there a way to do something like a msgbox but keep it on my Form (which is always in view) so I can go ahead and click a button on the form instead of having to bring the little msgbox window on top of windows that may be covering it.
I use the msgbox to inform me that a certain situation has happened, which I manually fix and when I'm done I click the MsgBox to continue processing. It'd be nice to have this button right on the form.
which I then have bring to the front if there is a window covering it
That shouldn't happen, but can happen if you display the message box from a thread in your program. The window has the desktop as the parent and has no Z-order relationship with the windows in your user interface. And yes, can easily disappear behind the window of another app, including your own.
There's a MessageBoxOptions option that isn't exposed in Winforms, MB_TOPMOST, which ensures the window is top-most. You'd use it like this:
MessageBox.Show("text", "caption", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0x40000); // use MB_TOPMOST
But by far the best thing to do is to display the message box on your UI thread. Use Control.Invoke() to do so. That way the other windows of your app are disabled, no way for the user to not notice the box.
Still one problem with this, the user won't expect the box to show up since it is shown asynchronously from anything she does. Which means the box can easily get dismissed by accident when the user just happened to press the Enter or Space key. Or clicked at just the wrong spot. Nothing much you can do about that.
Centering the box in your main window is technically possible, but fugly to do. Check this answer.
Do you mean that the form shall exchange its contents with a message plus an OK button?
This would be similar to the way a text mode interface typically works.
You can make it happen by adding a disabled panel or UserControl with message and button topmost on the form and enable it when you wish to alert the user. However, I am puzzled how to implement the blocking behavior similar to MessageBox.Show() and Dialog.Show().

Form.Show not showing up in Taskbar in Vista

I have a winform app that is hiding it's UI and waiting on a named pipe message before showing up
On receiving the event the thread invokes into the main UI thread and then does the following
Set the opacity to 100
ShowInTaskbar = true;
BringToFront();
ON Windows Vista the window does not show up on the taskbar though and the window is in the background . YOu cant say it
if you finally find it and click on it, it shows up on the taskbar
any ideas on how to fix this
i don't work in vista but it might be better just to flash the taskbar or do a ballon popup or something like that. What your suggesting maybe a bit annoying to a user. Say there typing away and there looking at the keyboard and your window has stolen the focus they look back and find what they just wrote hasn't gone into the app they thought it was going into.like this.
flashing the task bar
this might help also
If the form has an Owner set it might or might not show up in the taskbar.
Don't set the Owner property and it should show fine (it did for me).

Resources