Solution 1:

the code in your example used UIAutomation test script from Apple. I think you should read some documents about it.

Here is a tutorial of UIAutomation and a link to Apple document.

http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

Solution 2:

If you want to monitor a specific application U'll need to inject your RemoteControl SO ( or directly link it w/ the SO if U R the developer of the app ), re-sign the bundle with your dev profiles ( might req FairPlay removal on a separate Jail-Broken device ) and deploy it on your provisioned device.

If you want to monitor the device ( and not a specific app ), U'll need to:

  1. For screen capture you can use the new iOS8/Yosmite USB Screen mirroring feature ( see this link for details )
  2. For remote control, using the linux BlueZ Bluetooth stack, you can simulate a HID keyboard ( see this link for details )
  3. For a touch screen/mouse U'll need to Jail-break you device and install BTStack from cydia, OR, implement a HW Solution incorporating Apple Chips :(