4 Replies Latest reply: Jan 31, 2012 7:50 AM by thomanjones
hoopla_punta Level 1 Level 1 (0 points)
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)
  • 1. Re: How to get applescript or automator to ask system to "detect displays"
    V.K. Level 9 Level 9 (56,120 points)
    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.
  • 2. Re: How to get applescript or automator to ask system to "detect displays"
    jockebq Level 1 Level 1 (0 points)
    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?
  • 3. Re: How to get applescript or automator to ask system to "detect displays"
    roy_mccoy Level 1 Level 1 (0 points)

    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

  • 4. Re: How to get applescript or automator to ask system to "detect displays"
    thomanjones Level 1 Level 1 (0 points)

    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).