1

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 &
ocsav
  • 11
  • 2
  • for your script, use grep command to filter filename instead of tail, so it would be something like that : ls -tr /mydatadir/myfile-* | grep *.xlsx – damadam Dec 02 '19 at 15:26
  • tanks for trying to help but in this particular case the grep is not useful at all, even if I had other kind of files and I needed to select the right one, I would only have to add that to the ls, something like ls -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:11
  • It might make more sense to update your question with the current command used and the output it generates. – WinEunuuchs2Unix Dec 02 '19 at 18:15
  • But that's what I'm saying, I want an icon that when pressed opens a certain spreadsheet. The only detail is that the name of that spreadsheed it not fixed, the name of the file is given by ls -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

0 Answers0