In Ubuntu 16.04, I (eventually) want to drop a text file onto a desktop icon and get a Node.js app to run, treating the dropped file and outputting a new file.
I have discovered .desktop
files, and am doing my best to understand how to get the process to work, using a barebones set-up. I currently have three files: two files in a directory at /home/blackslate/Utilities/
and one on my desktop.
Utilities files
A text file named convert.js
:
const fs = require('fs');
const crypto = require('crypto');
const random = crypto.randomBytes(4).toString('hex');
const filename = random + '.txt'
fs.appendFile(filename, 'Hello ' + random + '!', function (err) {
if (err) throw err;
console.log(filename + ' saved');
});
An executable file named convert.sh
:
#!/bin/sh
node ./convert.js
gnome-terminal -e "bash -c 'echo hello world; sleep 3'"
Desktop file
An executable file named convert.desktop
:
[Desktop Entry]
Exec=gnome-terminal -e "/home/blackslate/Utilities/convert.sh \"%u\""
Icon=utilities-terminal
Type=Application
Name=Convert
Here's what happens:
If I call
node ./convert.js
from a Terminal window, I see that:- A new file is created and its name is shown in the Terminal window
If I call
./convert.sh
from a Terminal window, I see that:- A new file is created and its name is shown in the same Terminal window
- A second Terminal window is opened and says
hello world
before closing 3 seconds later
If I click on the Convert desktop file, I see that:
- One Terminal window opens, showing a bunch of text, and then it closes immediately
- A second Terminal window is opened and says
hello world
before closing 3 seconds later - No new text file is created
It is obvious that the second command in the convert.sh
file is being executed, but it appears that something is going wrong with the first one. What steps can I take to debug and fix this?
A .desktop can easily run a bash script
You should change things in your
convert.sh
:Note that you can redirect the output of node ./convert.js to a variable and use it as notification text...
MYVAR=$(node ./convert.js)
thennotify-send -t 3000 "Convert" "$MYVAR"
And you may make some changes in the
.desktop
filefind icons there
/usr/share/icons