-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (28 loc) · 847 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { exec } = require('child_process');
function clearString(string){
if (typeof string != 'string')
throw new Error('Passed object has not only strings');
return string.replace(/"/g, '').replace(/'/g, '');
};
function say(term = { message: 'I have nothing to say' }){
var obj = {
title: 'Mac notifier',
subtitle: false,
message: '',
};
if (typeof term === 'string')
Object.assign(obj, { title: term });
else {
if(typeof term != 'object')
throw new Error('Passed argument not object or string');
Object.assign(obj, term);
}
var phrase = 'osascript -e \'display notification "'+clearString(obj.message)+'"';
if(obj.title)
phrase += ' with title "'+clearString(obj.title)+'"';
if(obj.subtitle)
phrase += ' subtitle "'+clearString(obj.subtitle)+'"';
phrase += "'";
exec(phrase);
};
module.exports = say;