sbmpost / AutoRaise

AutoRaise (and focus) a window when hovering over it with the mouse
GNU General Public License v3.0
1.48k stars 60 forks source link
autofocus autoraise mouse osx

AutoRaise

When you hover a window it will be raised to the front (with a delay of your choosing) and gets the focus. There is also an option to warp the mouse to the center of the activated window when using the cmd-tab or cmd-grave (backtick) key combination. See also on stackoverflow

Quick start

  1. Download the disk image
  2. Double click the downloaded .dmg in Finder.
  3. In finder, look for mounted disk image on side bar at left.
  4. Drag the AutoRaise.app into the Applications folder.
  5. Then open AutoRaise from Applications.
  6. Left click the menu bar balloon at top to give permissions to AutoRaise in System/Accessibility.
  7. Right click the menu bar balloon at top, then select preferences.

Important: When you enable Accessibility in System Preferences, if you see an older AutoRaise item with balloon icon in the Accessibility pane, first remove it completely (clicking the minus). Then stop and start AutoRaise by left clicking the balloon icon, and the item should re-appear so that you can properly enable Accessibility.

Compiling AutoRaise

To compile AutoRaise yourself, download the master branch from here and use the following commands:

unzip -d ~ ~/Downloads/AutoRaise-master.zip
cd ~/AutoRaise-master && make clean && make && make install

Advanced compilation options

Example advanced compilation command:

make CXXFLAGS="-DOLD_ACTIVATION_METHOD -DEXPERIMENTAL_FOCUS_FIRST" && make install

Running AutoRaise

After making the project, you end up with these two files:

AutoRaise (command line version)
AutoRaise.app (version without GUI)

The first binary is to be used directly from the command line and accepts parameters. The second binary, AutoRaise.app, can be used without a terminal window and relies on the presence of a configuration file. AutoRaise.app runs on the background and can only be stopped via "Activity Monitor" or the AppleScript provided near the bottom of this README.

Command line usage:

./AutoRaise -pollMillis 50 -delay 1 -focusDelay 0 -warpX 0.5 -warpY 0.1 -scale 2.5 -altTaskSwitcher false -ignoreSpaceChanged false -ignoreApps "App1,App2" -stayFocusedBundleIds "Id1,Id2" -disableKey control -mouseDelta 0.1

Note: focusDelay is only supported when compiled with the "EXPERIMENTAL_FOCUS_FIRST" flag.

AutoRaise can read these parameters from a configuration file. To make this happen, create a ~/.AutoRaise file or a ~/.config/AutoRaise/config file. The format is as follows:

#AutoRaise config file
pollMillis=50
delay=1
focusDelay=0
warpX=0.5
warpY=0.1
scale=2.5
altTaskSwitcher=false
ignoreSpaceChanged=false
invertIgnoreApps=false
ignoreApps="IntelliJ IDEA,WebStorm"
ignoreTitles="\\s\\| Microsoft Teams,..."
stayFocusedBundleIds="com.apple.SecurityAgent,..."
disableKey="control"
mouseDelta=0.1

AutoRaise.app usage:

a) setup configuration file, see above ^
b) open /Applications/AutoRaise.app (allow Accessibility if asked for)
c) either stop AutoRaise via "Activity Monitor" or read on:

To toggle AutoRaise on/off with a keyboard shortcut, paste the AppleScript below into an automator service workflow. Then bind the created service to a keyboard shortcut via System Preferences|Keyboard|Shortcuts. This also works for AutoRaise.app in which case "/Applications/AutoRaise" should be replaced with "/Applications/AutoRaise.app"

Applescript:

on run {input, parameters}
    tell application "Finder"
        if exists of application process "AutoRaise" then
            quit application "/Applications/AutoRaise"
            display notification "AutoRaise Stopped"
        else
            launch application "/Applications/AutoRaise"
            display notification "AutoRaise Started"
        end if
    end tell
    return input
end run

Troubleshooting & Verbose logging

If you experience any issues, it is suggested to first check these points:

If after checking the above you still experience the problem, I encourage you to create an issue in github. It will be helpful to provide (a small part of) the verbose log, which can be enabled like so:

./AutoRaise <parameters you would like to add> -verbose true

The output should look something like this:

v5.3 by sbmpost(c) 2024, usage:

AutoRaise
  -pollMillis <20, 30, 40, 50, ...>
  -delay <0=no-raise, 1=no-delay, 2=50ms, 3=100ms, ...>
  -focusDelay <0=no-focus, 1=no-delay, 2=50ms, 3=100ms, ...>
  -warpX <0.5> -warpY <0.5> -scale <2.0>
  -altTaskSwitcher <true|false>
  -ignoreSpaceChanged <true|false>
  -invertIgnoreApps <true|false>
  -ignoreApps "<App1,App2, ...>"
  -ignoreTitles "<Regex1, Regex2, ...>"
  -stayFocusedBundleIds "<Id1,Id2, ...>"
  -disableKey <control|option|disabled>
  -mouseDelta <0.1>
  -verbose <true|false>

Started with:
  * pollMillis: 50ms
  * delay: 0ms
  * focusDelay: disabled
  * warpX: 0.5, warpY: 0.1, scale: 2.5
  * altTaskSwitcher: false
  * ignoreSpaceChanged: false
  * invertIgnoreApps: false
  * ignoreApp: App1
  * ignoreApp: App2
  * ignoreTitle: Regex1
  * ignoreTitle: Regex2
  * stayFocusedBundleId: Id1
  * stayFocusedBundleId: Id2
  * disableKey: control
  * mouseDelta: 2.0
  * verbose: true

Compiled with:
  * OLD_ACTIVATION_METHOD
  * EXPERIMENTAL_FOCUS_FIRST

2024-04-09 10:55:27.903 AutoRaise[40260:3886758] AXIsProcessTrusted: YES
2024-04-09 10:55:27.922 AutoRaise[40260:3886758] System cursor scale: 1.000000
2024-04-09 10:55:27.936 AutoRaise[40260:3886758] Got run loop source: YES
2024-04-09 10:55:27.975 AutoRaise[40260:3886758] Registered app activated selector
2024-04-09 10:55:27.995 AutoRaise[40260:3886758] Desktop origin (-1920.000000, -360.000000)
...
...

Note: Dimentium created a homebrew formula for this tool which can be found here:

https://github.com/Dimentium/homebrew-autoraise