Building a price tracker (Part 2 - Shortcuts and Application)

Code is done 💪.

Now, how can I make it so I don't have to open the terminal and type the command every time I want to track the price. Apple Shortcuts. I thought of doing it with Automator at first, but when I was programming it, I saw that Shortcuts had a few options that worked better.

Here's what I did (Windows users you'll need to look for an alternative, sorry 🤷🏼‍♂️):

Firstly, I had to execute the command, and Shortcuts, like Automator, has an action called "Run Shell Script" that does just that. What you need to keep in mind is that you need to specify the whole path, you cannot put node filename.js because it won't work. The path to node is /usr/local/bin/node and to reveal the path of your file, if you have VSCode open, right-click on the file and "Reveal Path".

copy-path.png

When you've copied the path, you paste it after the node path with a space in between. Should look like this:

run-shell-script.png

Now the interesting part. Do you remember the console.log at the end of the if statement? Well, when I did the first test, previous to the console.log I also had this line fs.appendFile("trackings-test.txt", result, function (err, data) {});

Once the shortcut was run, this was the output:

first-result.png

Then I went to the file, and it wasn't even modified. I tried many times, and I was always getting the result inside the app, but the text file was intact. Wondering what was going wrong, I commented the console.log and, right after the next execution, the output was empty. Shortcuts app was showing the console.log! 🤯

It was time for the next step, adding the result to a text file. I used the search bar to look for something to do with "text" and found what I was looking for:

text-search.png

I chose that action. Once it's in, you specify what you want to append, the folder where the file is and the file name. Should look like this:

append-to-text-file.png

Tried it and worked. Keep in mind that the first time you launch it, there will be a permission pop up asking you to let Shortcuts access the folder and write/modify files.

Now the text file was created, but I thought that if I wanted to check it when I wasn't at home, there will be no way for me. Then the Notes App came to my mind. I looked for the Notes app actions, and I didn't even have to look to the second option. The first one was what I needed.

append-to-note.png

Configuration is just what you want to paste and which note is going to be pasted. Keep in mind that you have to create the note before adding the action. append-to-note-view.png

Once that was set up, it was time for shortcut execution. As expected, it worked 🎉.

File text was created and filled and note also filled.

End of part 2