I use two monitors with my desktop computer (2009 iMac running the latest version of mountain lion). If I don’t turn on the second monitor it is still detected by the computer, and therefore screens are not gathered. I could turn on the screen and drag the window, but I can also toggle the mirror displays checkbox in system preferences on and then off.
So, I’ve been trying to find an applescript to do this. There are a number of posts discussing it but none which seem to work. And, all of them do it graphically with the system prefs opening.
My questions are
should it be possible to write an applescript that toggles mirror displays on and/or off?
should it be possible to do that without using the GUI? ie something that runs in the background
If it should be possible then I’ll spend a bit more time trying to find out how - unless someone has an already working script lying around
Cheers
Gareth
Browser: Safari 536.29.13
Operating System: Mac OS X (10.8)
Thanks for posting the code. This has been bugging me for a while. I’ll give it a try when I get home.
How difficult are these to write? I quite like the idea of having a folder in the dock which provides shortcuts to things in system preferences. Is there a list of these anywhere?
Quartz seems like a most interesting technology to learn.
I had a script for showing the preference pane for organizing screens, so I modified it a wee bit to toggle mirroring.
You’ll discover soon why Stefan’s solution is preferable.
-- Very slow fade-in / fade-out: just for prosperity, use StefanK's
tell application id "sevs" to if not (UI elements enabled) is true then set UI elements enabled to true
tell application "System Preferences"
reveal anchor "displaysArrangementTab" of pane "com.apple.preference.displays"
activate
tell application id "sevs"
tell window 1 of application process "System Preferences"
tell tab group 1
click radio button 2
click checkbox 1 of group 1
end tell
end tell
end tell
quit
end tell
I had tried scripts similar to the one you have posted. I’m especially grateful to Stefan as his method using command line is a much less clunky solution. Not seen it anywhere else on google.
Stefan
The commend runs fine. However when I put the file in my folders it introduces a space. When I run the script it returns an error. You suggest using the quoted form. Am I right to understand that as “/full/name/to path/”?
I agree totally. The showing up of the preferences pane, is one thing, ( I think of that as cool, rather than clunky), but StefanK has lowered the fade in / fade out times to an acceptable level. Because at least I have to wait until like forever, until the UIScript is done.
Then I urge you to try my script Stefan, because then I think UI Scripting or Applescript adds to the FadeIn/FadeOut.
The code would have been nice to see too, but I do understand if you want to keep it for yourself, I think I should be able to re-create something like it, should I need it.
I don’t know if it can be used with this but automator runs shell scripts, and I thought about adding it to that. My hope then was I could set up a workflow which runs the command twice (toggling on then off gathers the displays) and then quits terminal to lose the windows.
I may also eventually pluck up the courage to ask how to hide the terminal windows when the commend runs, but given what Stefan has done I feel that would be pushing things.