Just for clarification, I am nowhere near an expert! doing this simply for myself just to make my life a bit easier.I am attempting to control my PC using Alexa and IFTTT. I have a text document in Dropbox which I write to from IFTTT whenever I say a specific phrase, I am then using fs.watch() and whenever the file changes it checks if the text says the command (in this example "Spotify") then it overwrites the text in the text document, it then starts Spotify.However the issue I am facing is it opens said program twice. here is my code any help would be much appreciated!const fs = require('fs'); var exec = require('child_process').exec; fs.watch('test.txt', function(eventType, filename){ let fsWait = false; if (filename && eventType === 'change'){ if (fsWait) return; fsWait = process.nextTick(() => { fsWait = false; }, 100); fs.readFile('test.txt', function (err, data){ if (err) console.log(err); if (data.includes('spotify')){ fs.writeFile('test.txt', '', function (err, data){ if (err){ console.log(err) } }) exec('start C:\\Users\\myuser\\AppData\\Roaming\\Spotify\\Spotify.exe', function (err){ if (err){ console.log(err) } }) } }) } })
Submitted September 04, 2020 at 04:19AM by qt-anxiety
No comments:
Post a Comment