2

Sorry for the tags. I don't know whih one applies. Please remove not pertaining ones, then delete this line. Or comment, and I'll do it myself.

Background

I want to put a link to a file located in /home/myname/some/path/file.tex on my desktop. This TeX file calls other TeX files inside it. Now, when I open the link, which is located on the desktop, my TeX editor, it says I opened the file /home/myname/Desktop/file.tex. I can't compile this file, because the other TeX files the main TeX file relies upon are not located where the program expects them.

Main question

How can I make a link file open the target file in its actual location instead of on the desktop?

EDIT

The solution advertised here does not work as intended. With

#!/bin/bash
exec /home/myname/some/path/file.tex "$@"

I get

/tmp/geany_run_script_JVX1HZ.sh: 7: /tmp/geany_run_script_JVX1HZ.sh: ./open-file.sh: Permission denied


—----------------
(program exited with code: 126)
Press return to continue

Where open-file.sh is the wrapper script located on my desktop.

EDIT 2

Although, if I open a terminal and do

chmod a+x ./open-file.sh

and change exec to texstudio, which incidentally is the program I use to open .tex files, then I can open a terminal and do

bash open-file.sh

it will launch TeXStudio with the desired file loaded in the desired target location. I still can't just double-click open-file.sh on my desktop, since that will open my text editor, letting me edit the bash script. I want to double-click the open-file.sh script file and have TeXStudio open up my file.tex file.

### EDIT 3

From this question, I deduct that I have done everything right and the file should be clickable and be executed upon clicking. Unfortunately, it doesn't. I think my permissions are correct, afaik

enter image description here

and same here

-rwxr-xr-x me me 94 Apr 27 12:00 open-file
0

I don't know how to make a link itself work like this, but there's a relatively easy way to get it done.

The problem appears to be that program invoked to process your data is not running with its working directory set to the location of your data file.

Instead of linking the file itself, write a launcher script and pass your file location to it as a parameter. Then, link to the script from your desktop entry.

At least in KDE, this is easier to do by adding an entry to your Application Launcher with all the parameters set the way you want them and then dragging the entry from the menu to the desktop. It has a bunch of placeholder variables that let you modify the command and even lets you specify the working directory to use.

This could be simple or fancy. Start with simple:

#!/bin/bash
## Usage: launcheroo working-directory data-file
## defending this script is left as an exercise for the reader
## ... or you can ask in the comments ;)
cd "$1"
myprog "$2" ## or your more fancy exec that will figure out
            ## what program to run by itself

invoked as:

launcheroo path-to-data-files data-file

This handles the most basic usage, and illustrates the approach, but doesn't handle any errors like bad or missing parameters

To get a little fancier, you could extract the path from the specified data file path using dirname or bash parameter editing instead of passing it as a separate parameter.

A quick and dirty way to get this done - especially for testing how it works - would be to just edit the desktop icon to run

cd where-the-files-are ; exec ...

Since this is Linux, there are probably many other ways to do this as well.

If you add the file as an icon on the desktop, you can directly edit its .desktop file and get it to do all sorts of interesting things. I haven't done much with those.

Just saw this answer which is essentially the same as mine with a slightly different spin to it.

  • A faint idea in the style of "and get it to do all sorts of interesting things" is what got me to start using linux in the first place, but as I'm not a programmer and find it hard to get into the matter without a direct tutor, since I have a day job I try to do to the best of my abilities, it's very hard for me to get the machines do my bidding. Thanks for the answer, I'll look into it. – thymaro May 3 '18 at 11:43
  • Everyone has different skills and priorities.That's what makes the world work. I'd be happy to do a step by step on this, but it should probably be done outside of the Q&A here. I don't know how to get from here to there without publishing my personal email address, etc. I'll see what they say on meta. – Joe May 3 '18 at 21:35
  • uhm... you can hit me up on telegram, github or twitter. I use the same handle on those three as on the SE network. are such comments allowed, when not explicitly posting the respective links? – thymaro May 4 '18 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.