index.js
function send(handle, message) {
    assert(typeof handle == 'string', 'handle must be a string')
    assert(typeof message == 'string', 'message must be a string')
    return osa((handle, message) => {
        const Messages = Application('Messages')

        let target

        try {
            target = Messages.buddies.whose({ handle: handle })[0]
        } catch (e) {}

        try {
            target = Messages.textChats.byId('iMessage;+;' + handle)()
        } catch (e) {}

        try {
            Messages.send(message, { to: target })
        } catch (e) {
            throw new Error(`no thread with handle '${handle}'`)
        }
    })(handle, message)
}
function send(handle, message) {
    assert(typeof handle == 'string', 'handle must be a string')
    assert(typeof message == 'string', 'message must be a string')
    return osa((handle, message) => {
        const Messages = Application('Messages')

        let target

        try {
            target = Messages.buddies.whose({ handle: handle })[0]
        } catch (e) {}

        try {
            target = Messages.textChats.byId('iMessage;+;' + handle)()
        } catch (e) {}

        try {
            Messages.send(message, { to: target })
        } catch (e) {
            throw new Error(`no thread with handle '${handle}'`)
        }
    })(handle, message)
}
function send ( handle , message ) { assert ( typeof handle == 'string' , 'handle must be a string' ) assert ( typeof message == 'string' , 'message must be a string' ) return osa ( ( handle , message ) => { const Messages = Application ( 'Messages' ) let target try { target = Messages . buddies . whose ( { handle : handle } ) [ 0 ] } catch ( e ) { } try { target = Messages . textChats . byId ( 'iMessage;+;' + handle ) ( ) } catch ( e ) { } try { Messages . send ( message , { to : target } ) } catch ( e ) { throw new Error ( ` ${ handle } ` ) } } ) ( handle , message ) }
Sends a message to the given handle
Sends a message to the given handle