Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.