Skip to content

Instantly share code, notes, and snippets.

@arronmabrey
Created September 16, 2016 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arronmabrey/c59768f5191503b8d5f9eabfa7e49571 to your computer and use it in GitHub Desktop.
Save arronmabrey/c59768f5191503b8d5f9eabfa7e49571 to your computer and use it in GitHub Desktop.
ios-type2phone-cli.swift
#!/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