Created
September 16, 2016 16:11
-
-
Save arronmabrey/c59768f5191503b8d5f9eabfa7e49571 to your computer and use it in GitHub Desktop.
ios-type2phone-cli.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env swift | |
import Foundation | |
print("Enter keycode to send: ", terminator: "") | |
if let keycode = readLine() { | |
print("set keycode = \(keycode)") | |
let appleScript = "tell app \"Type2Phone\" to sendKeyCode \(keycode)" | |
print("set appleScript = \(appleScript)") | |
if let scriptObject = NSAppleScript(source: appleScript) { | |
var appleScriptCompileError: NSDictionary? | |
scriptObject.compileAndReturnError(&appleScriptCompileError) | |
if (appleScriptCompileError != nil) { | |
print("appleScriptCompileError: \(appleScriptCompileError)") | |
exit(1) | |
} | |
print("scriptObject.isCompiled = \(scriptObject.isCompiled)") | |
print("ready... press [ENTER] to send \(keycode)") | |
while readLine() != nil { | |
var execError: NSDictionary? | |
scriptObject.executeAndReturnError(&execError) | |
if (execError != nil) { | |
print("execError: \(execError)") | |
exit(1) | |
} | |
print("\(keycode)", terminator: "") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment