Last active
December 3, 2024 12:00
-
-
Save lexjacobs/a65dfcc8c7d28ac667de4cc09de8120a to your computer and use it in GitHub Desktop.
When plugging or unplugging external monitor via hdmi cable, sometimes the change in external display won't register. This is an applescript to automate the process of using the display menu "detect displays" button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env osascript | |
# adapted from https://stackoverflow.com/a/12641263/3044358 | |
# don't forget to | |
# chmod 744 detect-displays.command | |
tell application "System Preferences" | |
activate | |
reveal pane "com.apple.preference.displays" | |
end tell | |
delay 0.5 | |
tell application "System Events" | |
tell process "System Preferences" | |
try --don't even consider not using a try block! | |
key down option | |
delay 0.2 | |
click button "Detect Displays" of window 1 | |
delay 0.2 | |
key up option | |
on error --logging out is the only other way to clear these | |
key up option | |
end try | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment