Skip to content

Instantly share code, notes, and snippets.

@v1c77
Last active April 14, 2024 04:25
Show Gist options
  • Save v1c77/96affa87de94045d29cdc5f9cb8c1847 to your computer and use it in GitHub Desktop.
Save v1c77/96affa87de94045d29cdc5f9cb8c1847 to your computer and use it in GitHub Desktop.
rotate display using applescript, tested on Mac os High Sierra(10.13)
--
-- Created by: v1c77
-- Created on: 2018/7/21
--
-- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-- Version 2, December 2004
-- Copyright (C) 2020 v1c77
-- Everyone is permitted to copy and distribute verbatim or modified
-- copies of this license document, and changing it is allowed as long
-- as the name is changed.
-- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-- 0. You just DO WHAT THE FUCK YOU WANT TO.
use AppleScript version "2.7" -- Yosemite (10.10) or later
use scripting additions
tell application "System Preferences"
quit
delay 0.5
launch
activate
set current pane to pane "com.apple.preference.displays"
--reveal pane id "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
tell window "DELL U2415" -- change the window name for different display
delay 1
click radio button "Display" of tab group 1
set theGroup to tab group 1
tell pop up button "Rotation:" of theGroup
set theStat to value of it
click
tell menu 1
if theStat = "Standard" then
click menu item 4 -- 270 dig
else
click menu item 1 -- standard
end if
end tell
end tell
end tell
end tell
end tell
tell application "System Preferences"
quit
end tell
@alissoneloi
Copy link

On my Mac air M2 (Ventura 13.3.1a)

error "System Events got an error: Can’t get application process "System Settings"." number -1728 from application process "System Settings"

@felipemldias
Copy link

Hi @alissoneloi, did you find and alternative to bypass the error message? I've found that if I activate it twice, it opens without any issues

@lucasmalaguti
Copy link

tried on Sonoma with no success

@arootroatch
Copy link

I just upgraded to Ventura and am also getting the error System events got an error: Can't get window "Displays" of application process "System Settings"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment