I think I've fixed it. I don't know who makes LyX/Mac, but whoever does should really rethink the design a little. I'll start by describing how I was able to make LyX.app run anywhere. I don't know if anything else was broken, but it will certainly launch, edit, and save documents. If it breaks anything, though, it could rightly be regarded as a bug in LyX, since I am only calling the app with an argument that should remove the directory dependence.

First, I changed the property stored in Lyx.app/Contents/Info.plist to point to a shell script (LyX.sh) instead of the original executable. To make this take effect, I had to reboot (I believe that unmounting and remounting the disk LyX.app is on is sufficient, but when that's the startup disk). Note that the shell script must be placed in LyX.app/Contents/MacOS/.

Now, for the contents of said shell script:

#! /bin/sh

exec `$0"_pathmaker"`

It turns out that the exec command is the key to making LyX responsive upon launch from a shell script. $0 gives the command name of the script (in this case, the full path), and I concatenate that with "_pathmaker" in order to run a C app I coded to put together the command for launching LyX using the path to the command as a basis. If I knew how to do that string manipulation in the shell script, that would be preferable. Nevertheless, here is the source code for LyX.sh_pathmaker:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char * argv[]) {
  char * command;
  int L = strlen(argv[0]);

  command = (char *) malloc((2*L + 30)*sizeof(char));
  if (command != NULL) {
    strncpy(command, argv[0], L - strlen("LyX.sh_pathmaker"));
    strcat(command, "LyX -sysdir ");
    strncat(command, argv[0], L - strlen("MacOS/LyX.sh_pathmaker"));
    strcat(command, "Resources/LyX/");
    printf(command);
  }
  else {
    printf("echo \"Error allocating command buffer\n\"");
  }
  free(command);
  return 0;
}

There are, of course, lots of optimizations that could be performed, but this is the most bulletproof and readable implementation I could come up with.

Ideally, though, the maker of LyX/Mac would combine the run anywhere functionality I've scraped together above in to the code of Start-LyX (applescript can do the string munging I've done in C, I'm sure), and incorporate Start-LyX in to the LyX.app bundle.

Oh, yeah, note that the above breaks Start-LyX because it too uses hard coded directories.

Sean
On Nov 24, 2003, at 12:52, Sean wrote:

How do I get LyX to work in a directory besides /Applications/? Specifically, I want to stick it in a subdirectory /Applications/Productivity/. LyX, for some reason, has the path /Applications/ internally hard coded (you can check this with a hex editor - just search for the path). I can get it to run from the command line by launching it with an absolute path an giving it the argument -sysdir, but I can't figure out how to make it back in to a double-clickable app. I've tried moving the executable and replacing with either a shell script and a compiled c executable (both just running the command I would enter in the CLI), but LyX will launch frozen (even if a attach an & to the end of the command).

Is there any way to get LyX to be a double clickable, run anywhere app? In theory, this would entail some kind of script (shell or apple) that would figure out the full path of the program, and launch it with the appropriate arguments. Even better would be if the executable itself did this, but there may be some obscure technical reasons I'm unaware of why it cannot.

Sean




Reply via email to