This is related with Execute sh script from *.desktop file? but here the OP asks how to call a bash script from an icon.
I want to write a shell script that is called from an icon and return the name of a file (in this case a .xlsx
). In a webserver I would just return the correct mime type but I have no idea of what I need to do in the GNOME context.
My script would be something like
#!/bin/bash
X=$(ls -tr /mydatadir/myfile-* | tail -1)
echo $X
Thanks in advance.
This works, but not in the way I want. Here I'm calling the program that handles myfile directly from the script. I want the script to find out the name, return it to Gnome and let Gnome handle it. It's like when you have a script on a webserver when you return the mime type for something like a GIF and then return the data, and the browser knows how to make that look like a picture. It must (I think) be possible to do something like that with the Gnome desktop.
file: ~/Desktop/myfile.desktop
[Desktop Entry]
Name=Last Myfile
Comment=Open Last Myfile version
Icon=/usr/share/icons/Adwaita/32x32/mimetypes/x-office-spreadsheet.png
Exec=/home/myself/bin/last_myfile.sh
Type=Application
Terminal=false
Encoding=UTF-8
Categories=System;
file: /home/myself/bin/last_myfile.sh
#!/bin/bash
DIR="/home/myself/CLIENT/myfile"
X=$(ls -tr $DIR | tail -1)
nohup /usr/lib64/libreoffice/program/oosplash --calc file://$DIR/$X &
grep
command to filter filename instead oftail
, so it would be something like that :ls -tr /mydatadir/myfile-* | grep *.xlsx
– damadam Dec 02 '19 at 15:26ls -tr /mydatadir/myfile-*.xlsx | tail -1
. The problem is how to make the gnome open a file wich name is returned by the script. The "tail -1" returns the last file in the list, ls -tr lists the files in reverse order. So, what I'm doing here is writing the name of the last file to arrive at that dir. – ocsav Dec 02 '19 at 16:11ls -tr /mydatadir/myfile-*.xlsx | tail -1
. I am able to doit if I call the spreadsheet program from the script with nohup and &, that works ok, but I wanted that the spreadsheet program to be called by gnome according to what's defined to that type of file. That looks to be the right way to do it even if the effect is the same. – ocsav Dec 03 '19 at 15:17