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

Applescript to turn Airplay Mirroring on

Hi all,


I am having a little trouble with this applescript which is intended to turn Airplay Mirroring onto my Apple TV. Any help would be greatly appreciated as I'm really new to applescript.


tell application "System Preferences" to activate

tell application "System Events" to tell process "System Preferences"

tell menu 1 of window 1

set value of airplaymirroring to "Apple TV"

end tell

end tell

quit application "System Preferences"

iMac (27-inch, Late 2012), OS X Mountain Lion (10.8.4)

Posted on Sep 19, 2013 10:44 AM

Reply
5 replies

Sep 19, 2013 9:41 PM in response to arrrrrrgh

tell application "System Preferences"

set current pane to pane "com.apple.preference.displays"


activate

end tell


tell application "System Events"

tell process "System Preferences"


clickpop up button 1 of window 1


clickmenu item 2 of menu 1 of pop up button 1 of window 1

end tell

end tell


tell application "System Preferences"


quit

end tell




Oguz ARDUC: Applescript for Activating Airplay Mirroring on OS X ...



Sep 20, 2013 7:31 AM in response to nbar

Thanks for your help,


I had come across this script and it works. I also found this one from


http://forums.macrumors.com/archive/index.php/t-1587586.html


which works a little better in my view, because it doesn't pop up the pref window, only flickers the menu bar


tell application "System Events"

tell process "SystemUIServer"

click (menu bar item 1 of menu bar 1 whose description contains "Displays, AirPlay Off")

click menu item "Apple TV" of menu 1 of result


delay 5

end tell

end tell


Ideally I'd like to find/create a script that runs purely in the background (I found one to set the output sound to Apple TV in a hidden way) so as not to confuse my wife <g>


Again, thanks for the help.

Mar 6, 2016 4:46 AM in response to Moothor

The most simple and reliable way I have found to do this is to have applescript click on the Displays Menu item in menu bar 1 and then use keystrokes to arrow down to the correct item and then press return.


For some reason, Yosemite doesn't seem to want to enumerate the sub menu which is why the scripts above have stopped working.


Your sub menu may be different from mine if you have more airplay devices or if your displays appear in a different order. You may need to add more keystrokes to choose the right item from the sub menu. Key code 125 is down arrow, add more of those if you need menu items further down the list.


tell application "System Events"

tell process "SystemUIServer"

click (menu bar item 1 of menu bar 1 whose description contains "Displays Menu")

key code 125

keystrokereturn

delay 5

end tell

end tell

Applescript to turn Airplay Mirroring on

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