jump to navigation

Mirror, mirror on my Mac April 2, 2009

Posted by bigmaconcampus in Mac Tech.
trackback

While working on a lockdown mechanism recently, I needed to activate mirroring on displays when necessary via command-line. The method uses Applescript and GUI scripting, not my preferred method but does what it needs.

In the applescript, I pass it a variable from the parent script, either on or off and expect to possibly get a returned variable of true, if applicable, so I can run the command again later if I need to turn mirror mode back off.

*Note* Scripts tend to cut off visually on screen. You can copy/paste the script to grab it.


on run argv
set TOGGLE to item 1 of argv
if TOGGLE is "on" then
set TOGGLE to "1" as integer
else
set TOGGLE to "0" as integer
end if
try
tell application "System Preferences"
activate
reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"
tell application "System Events"
tell application process "System Preferences"
tell window 1
tell group 1 of tab group 1
if value of checkbox "Mirror Displays" is not TOGGLE then
set TurnOffMirror to "true"
click checkbox "Mirror Displays"
tell application "System Preferences" to quit
return TurnOffMirror
end if
end tell
end tell
end tell
end tell
end tell
on error
tell application "System Events"
tell application process "System Preferences"
keystroke return
end tell
end tell
end try
tell application "System Preferences" to quit
end run

An alternative I found works well, but didn’t totally fit my needs. It toggles mirror mode on and off. I need it to toggle only under certain circumstances. Still, might be useful to someone else, and best of all it’s open source.

http://www.fabiancanas.com/Fabian_Canas/Projects/Entries/2009/2/4_Mirror_Displays.html

Advertisements

Comments»

1. Fabian - April 3, 2009

So I’m the author of the MirrorDisplays program @ http://www.fabiancanas.com/Fabian_Canas/Projects/Entries/2009/2/4_Mirror_Displays.html

It’s nice to see that it might be useful to someone. I was wondering what “certain circumstances” you needed the toggle to happen on. I’d be glad to help you adapt the code for your needs. Is it part of an open source project?

Fabian - April 7, 2009

I never heard back about what you needed, but I figured I should let you know that the command line tool I wrote now accepts arguments.

mirror -on
mirror -off

This makes the tool quite a bit more useful for scripting. I hope this makes it more useful to you.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: