I have a logitech wireless mouse hooked up to a macbook pro running 10.7. Whenever I middle-click the mouse button, the laptop's display brightness decreases. It behaves just as if I had pressed the F1 key. The middle-click still works in applications (e.g. Firefox opens a new tab), it just has this annoying side-effect. How can I correct this behavior?
MacOS – Screen brightness decreases when I middle-click
displaymacosmouse
Related Solutions
Try holding the Command button instead. A Command click is a middle click. Control clicks give you a right click.
What kind of Mac? If you're using a Magic Mouse you can use a program like MagicPrefs to turn a three finger click into a Command click. If you're using the Magic Trackpad or the built-in trackpad on a MacBook/MacBook Pro there is a program called MiddleClick I've used that adds a three finger tap/click ability to map to the Command click.
I think this will do what you're asking. I've modified your original code to see what process is frontmost at the time it's run, in order to branch and test appropriately based on the conditions expressed in your question by use of checkModifierKeys
*. to see if the ⌘ command key was pressed when Google Chrome is the frontmost process at the time the service is run. *(I have no affiliation with Charles Poynton’s blog or Stefan Klieme’s checkModifierKeys other than to have been using this program for a few years without issue.)
As coded, it assumes that the checkModifierKeys
is located in /usr/local/bin/
. Modify as needed.
See the comments in the if theFrontmostProcessWhenRun is "Google Chrome" then
block for its logic flow.
on run {input, parameters}
-- # Get the name of frontmost process at the time the services was run.
-- #
-- # This is used later in an if statement block for when if Google Chrome was frontmost process when run
-- # to check that the value returned from checkModifierKeys was for the command key being pressed.
tell application "System Events"
set theFrontmostProcessWhenRun to get name of process 1 where frontmost is true
end tell
(*
When triggering this Service in applications other than Google Chrome, such as TextEdit, the Chrome window opens in the background. This command brings the Chrome window to the foreground:
*)
activate application "Google Chrome"
(*
Converting the selected text to plain text to remove any formatting:
From: http://lifehacker.com/127683/clear-text-formatting-on-os-x
*)
set selectedText to input
set selectedText to (selectedText as text)
(*
Removing any line breaks and indentations in the selected text:
From: http://stackoverflow.com/a/12546965
*)
set AppleScript's text item delimiters to {return & linefeed, return, linefeed, character id 8233, character id 8232}
set plainTextSelectedText to text items of (selectedText as text)
set AppleScript's text item delimiters to {" "}
set plainTextSelectedText to plainTextSelectedText as text
(* Assigning variables: *)
set baseURL to "https://www.google.com/search?q="
set finalLink to baseURL & plainTextSelectedText
(* Opening webpage in Chrome: *)
(*
The following tell block creates a new tab, located immediately after the currently open tab, which is what I want to occur.
From: http://apple.stackexchange.com/questions/271702/applescript-how-to-open-a-link-in-google-chrome-in-a-new-adjacent-tab/271709#271709
*)
if theFrontmostProcessWhenRun is "Google Chrome" then
-- # Google Chrome was the frontmost process when the service was run.
if ((do shell script "/usr/local/bin/checkModifierKeys") as integer) is equal to 256 then
-- # The command key was pressed when the service was run.
tell application "Google Chrome"
-- # See Note: below.
set activeTab to active tab index of front window
tell front window to make new tab at after (get active tab) with properties {URL:finalLink} -- open a new tab after the current tab
set active tab index of front window to activeTab
end tell
else
tell application "Google Chrome"
tell front window to make new tab at after (get active tab) with properties {URL:finalLink} -- open a new tab after the current tab
end tell
end if
else
-- # Google Chrome was not the frontmost process when the service was run.
tell application "Google Chrome"
tell front window to make new tab at after (get active tab) with properties {URL:finalLink} -- open a new tab after the current tab
end tell
end if
end run
Note: When Google Chrome is frontmost at the time the service is run and the ⌘ command key is pressed, this gets the current active tab index
and sets it back to it after making the new tab. This is intended as a workaround as it's a bit kludgy, but better then nothing until a more elegant solution to a problem can be found.
Best Answer
What you need to do is change the key mappings on your mouse. What this does is tells your computer what to do when you press key X.
For Mac…
For Windows…