Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to get applescript or automator to ask system to "detect displays"

I want to know how to get automator or applescript to "detect displays" (which is found in Displays prefpane). Thanks.

Macbook 2.4 GHz, Mac OS X (10.5.4)

Posted on Aug 13, 2008 6:42 AM

Reply
4 replies

Aug 13, 2008 7:10 AM in response to hoopla_punta

this can only be done with GUI scripting so make sure that access to assistive devices is enabled in Universal Acccess system preferences and put the displays menu in the menu bar.

then the following apple script will work.


<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
tell (first menu bar item whose value of attributes contains "displays")
click
tell 1st menu item of front menu
click
end tell
end tell
end tell</pre>

Message was edited by: V.K.

Feb 20, 2009 2:30 AM in response to V.K.

I have tried youre script, i'm a newbie at OSX, but i opened Automator and dragged it in, saved it as an application, and when i run it nothing happens 😟
If it matters my operating system is in Swedish (10.5.6), tho i tried changing the language to english and run it, it did not work either.

I would love to make this work, so V.K. if you see this, please reply. Maybe i aint doing it right?

Jun 27, 2011 4:02 AM in response to jockebq

Sorry I'm late, but this page was the only Google find on "script detect displays"

when I checked on June 26, 2011. The script commands worked immediately for

me and I offer V.K. belated thanks if he/she is still around for having solved this

longstanding problem for me. I had written a script earlier trying to do this, but it

didn't work reliably so I gave up on trying to use it.


If jockebq is by chance still around, I would recommend that he/she try doing as

I did and use a more simple version of the script, namely:


tell application "System Events" to tell the front menu bar of process "SystemUIServer"

tell (first menu bar item whose value of attributes contains "displays")

click

tell 1st menu item of front menu

click

end tell

end tell

end tell


I have this saved as a normal .scpt script and assigned to ctrl-opt-shift-d

in QuicKeys. It works every time.



Roy McCoy

Rotterdam, NL

Jan 31, 2012 7:50 AM in response to roy_mccoy

Roy's Script works like a charm in Lion as well. I opened up appleScript, copy & paste, did a test run, and saved it as an Application. Now when I plug in my janky work monitor and lose my main screen, I just have to hit command+space , type detect and hit enter.


If anyone has any issues with the script, make sure you have assistive devices turned on, and displays in your menu bar (both can be set in system preferences).

How to get applescript or automator to ask system to "detect displays"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.