Skip navigation

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

2826 Views 4 Replies Latest reply: Jan 31, 2012 7:50 AM by thomanjones RSS
hoopla_punta Calculating status...
Currently Being Moderated
Aug 13, 2008 6:42 AM
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)
  • 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.
    Mac Pro 3.2 GHz, Mac OS X (10.5.4), Mac Pro 2.66GHz, powerbook G4 1.5GHz
  • jockebq Calculating status...
    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?
    Mac OS X (10.5.6)
  • roy_mccoy Calculating status...

    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

  • thomanjones Calculating status...

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

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.