launching livecode files in Windows in one instance of LiveCode
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
launching livecode files in Windows in one instance of LiveCode
In Windows 11 double clicking a .livecode file (application extension:.livecode, .rev) opens that file in a new instance of LiveCode.exe which I want to prevent. I want to open the file in the IDE of the currently executing LiveCode instance as if opening from the IDE. Maybe I have overseen a solution to this, or I cannot find a solution despite searching. I can prevent LiveCode from starting another process using system tools, but that does not help since the LIveCode file shall still open which is not possible stopping a new process.
Any suggestions? Roland
Any suggestions? Roland
Re: launching livecode files in Windows in one instance of LiveCode
Hi Roland,
check "relaunch" in the dictionary, sounds like that is what you need.
Best
Klaus
check "relaunch" in the dictionary, sounds like that is what you need.

Best
Klaus
Re: launching livecode files in Windows in one instance of LiveCode
Klaus, thank you for your reply. I had checked that. It does not work in the IDE, only for standalones.
Re: launching livecode files in Windows in one instance of LiveCode
Hi Roland,
hm, if I remember correctly, this is the official way to do so.
Sorry, was in a hurry yesterday. Did you add a handler like this to your stack
that should be opened after the IDE had started:
Best
Klaus
hm, if I remember correctly, this is the official way to do so.
Sorry, was in a hurry yesterday. Did you add a handler like this to your stack
that should be opened after the IDE had started:
Code: Select all
##Stackskript or script of first card:
on relaunch
### NADA
end relaunch
Klaus
Re: launching livecode files in Windows in one instance of LiveCode
Klaus:
is not recognized in the IDE. It does not fire.
I cannot think of any solution that is simply scriptable. When opening a file from anywhere except from inside a running instance, a new instance is started. In some cases, this may be desired. In most cases, I do not want it.
What I could do is check with a command line program if an instance of LiveCode.exe is running, and if YES, then intercepting every call to LiveCode.exe on the system level (redirecting to a message sending app using regedit) and using sockets in a library stack that would receive the path of the file to be opened as the message.
The running LiveCode.exe process would then be opening the file processing the message received. But it is no-standard, and it requires Admin rights to install -- at least I think so. I must check it. Possibly, an external C-program hooked into LiveCode could also do this directly inside of LiveCode.exe. I am not sure and not knowledgeable enough to work on this. And I also doubt that LiveCode builder could help here. But what do I really know?
I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.
Code: Select all
on relaunch
-- quit ---- :-)
end relaunch
I cannot think of any solution that is simply scriptable. When opening a file from anywhere except from inside a running instance, a new instance is started. In some cases, this may be desired. In most cases, I do not want it.
What I could do is check with a command line program if an instance of LiveCode.exe is running, and if YES, then intercepting every call to LiveCode.exe on the system level (redirecting to a message sending app using regedit) and using sockets in a library stack that would receive the path of the file to be opened as the message.
The running LiveCode.exe process would then be opening the file processing the message received. But it is no-standard, and it requires Admin rights to install -- at least I think so. I must check it. Possibly, an external C-program hooked into LiveCode could also do this directly inside of LiveCode.exe. I am not sure and not knowledgeable enough to work on this. And I also doubt that LiveCode builder could help here. But what do I really know?

I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: launching livecode files in Windows in one instance of LiveCode
A unique application would need a unique file extension to distinguish its document type.
Once you do that, Klaus did not lead you astray: the relaunch message is indeed the way to prevent documents from launching a new instance, instead opening in the running instance.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: launching livecode files in Windows in one instance of LiveCode
I just made a test and it works as I told you!
1. I created a new stack "test1" with this "dummy" handler in the script of its first cd:
2. I closed it and created another stack.
3. I double-clicked the stack "test1" and it was opended in the already running instance of Livecode.
Did you try exactly this?
1. I created a new stack "test1" with this "dummy" handler in the script of its first cd:
Code: Select all
on relaunch
##
end relaunch
3. I double-clicked the stack "test1" and it was opended in the already running instance of Livecode.
Did you try exactly this?
Re: launching livecode files in Windows in one instance of LiveCode
Yes, I tried exactly this. Even before writing of course. You are on Windows?
That is interesting. Are there any settings that may be different?
That is interesting. Are there any settings that may be different?
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: launching livecode files in Windows in one instance of LiveCode
What file extension are you using for your LiveCode stackfile documents?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: launching livecode files in Windows in one instance of LiveCode
Just to make sure that I am not mistake, I tested it with three different stacks.
The script is in the stack script. The stack is not dependent on any other stack or resources.
Now, for example, saving a copy of the stack to the same folder the running stack is located, and double-clicking that file, opens the file in another window and launches LiveCode as a new instance. Having done this twice, there are now two menu bars, to tools-palettes, etc.
The handler for such an event is never triggered and does not receive such message even though it should (or not)?
The dictionary finally states:
The dictionary also says:
The script is in the stack script. The stack is not dependent on any other stack or resources.
Code: Select all
on relaunch
##
end relaunch
The handler for such an event is never triggered and does not receive such message even though it should (or not)?
The dictionary finally states:
What does it mean? What is double clicking in a file in the Windows shell? I am running latest version of Windows 11 and the latest LiveCode 9.6.13. But whatever the configuration -- I also tested on other machines -- the result is the same."Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
The dictionary also says:
Maybe there is some hint in here? The $n global?If there are no existing instances, the new instance will run.
The relaunch message is passed a variable number of arguments depending on the command-line the new instance is started up with. The processing is the same that is performed for the $n global variables before application startup. i.e. the command-line string is split into words, each word has any leading and trailing quotes stripped and '\' is replaced by '/'.
Re: launching livecode files in Windows in one instance of LiveCode
Hi Roland
Best
Klaus
I started a VM machine (via Paralells on my Mac) with Win11 for testing.
No, this is a fresh installation, did not set anything in Windows so far.
Best
Klaus
Re: launching livecode files in Windows in one instance of LiveCode
this just means double-clicking a LC file on the desktop or any open folder.golife wrote: ↑Thu Oct 03, 2024 11:11 pmThe dictionary finally states:What does it mean? What is double clicking in a file in the Windows shell?"Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
I also means that the "dummy" handler is not even neccessary, the IDE takes care of this.
So if this is not the case for you, then there is something else going on on your machine!
Try to de-install and re-install LC, maybe that will help
Re: launching livecode files in Windows in one instance of LiveCode
Yes, as I said from the beginning, the relaunch handler only seems to work in a standalone, as the dictionary states. Yes, I am using Windows 11 latest version. Klaus made another observation, but I cannot reproduce. I am uskng .livecodei or .rev as the file extensions.
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: launching livecode files in Windows in one instance of LiveCode
Those file extensions are associated with the LiveCode application. That's the missing piece here, file associations.
There really should be a more complete Lesson on document handing, but this tutorial from Ken Ray will point you in the right direction:
http://sonsothunder.com/devres/livecode ... ile004.htm
In short, OSes need some way to know which file types are associated with which apps. On macOS this is done in the plist file included inside the application bundle. On Windows this is handled in the Windows Registry.
That tutorial shows how LiveCode can be used to read and write the appropriate Registry entries to associate your unique file type with your application.
Please note it will need to be a unique file type. File type extensions matter to the OS, but not to the LC engine. The engine can open any valid LC stack file regardless of its file extension.
When opening from within LC this is simple and automatic; scripting "open stack <file path> just works.
It's the part involving the Windows File Explorer, either dragging your document file icon to the app or double clicking it, where the appropriate Registry entry is needed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: launching livecode files in Windows in one instance of LiveCode
Unless I am misreading, I think the file association is fine.
Double-clicking a file with (eg) extension of .rev will open that file in the IDE.
The problem for the OP is that once opened in the IDE, then double-clicking the same file will also open it, in a new instance of the IDE.
What should normally happen, I believe, is that the original instance of the IDE would attempt to open the file, but halt with a prompt to the user advising a stack with that name is already open, and to choose whether to close, or purge the original.
I don't know why two IDE instances would be initiated.
Double-clicking a file with (eg) extension of .rev will open that file in the IDE.
The problem for the OP is that once opened in the IDE, then double-clicking the same file will also open it, in a new instance of the IDE.
What should normally happen, I believe, is that the original instance of the IDE would attempt to open the file, but halt with a prompt to the user advising a stack with that name is already open, and to choose whether to close, or purge the original.
I don't know why two IDE instances would be initiated.