import { exec } from 'child_process'; import { config } from '../config'; export const sendMessage = (to: string, message: string): Promise => { return new Promise((res, rej) => { exec( `osascript -e 'tell application "Messages" to send "${message}" to buddy "${to}"'`, (err, stdout, stderr) => { if (err) { return rej(err); } if (stderr) { console.error(stderr); } if (!stdout) { return res(''); } try { return res(stdout.toString()); } catch (e) { return rej(e); } }, ); }); }; export const sendAttachment = (to: string, path: string): Promise => { return new Promise((res, rej) => { exec( `osascript "${config.sendAttachmentScriptPath}" "${to}" "${path}"`, (err, stdout, stderr) => { if (err) { return rej(err); } if (stderr) { console.error(stderr); } if (!stdout) { return res(''); } try { return res(stdout.toString()); } catch (e) { return rej(e); } }, ); }); };