Starting an app from a data file and waiting for it to complete

I have a data file eg, test.jpg
If I use getfolderitem(“test.jpg”).launch
It will open it with the associated program.

However, I need to know when the program ends so I can check the data file for changes (ignore they may save it elsewhere)
However launch does not seem to have a way to inform me when its lauched process completes.

So, I could create an interactive shell, but what OSX/Win command do you use to lauch a datafiles associated application?
or is this possible somehow in Xojo.

[quote=107722:@dave duke]I have a data file eg, test.jpg
If I use getfolderitem(“test.jpg”).launch
It will open it with the associated program.

However, I need to know when the program ends so I can check the data file for changes (ignore they may save it elsewhere)
However launch does not seem to have a way to inform me when its lauched process completes.

So, I could create an interactive shell, but what OSX/Win command do you use to lauch a datafiles associated application?
or is this possible somehow in Xojo.[/quote]

You can use open <path to the file> in OSX.

On a PC, Start <Path to file>

Let me understand what you want to achieve.

This is what I understood :

  • You launch test.jpg
  • This opens the default program for jpg (you can also impose a program of your choice)
  • The user does whatever he needs to do to the file
  • The user closes the program that edits jpg
  • You need to know that program was closed so you can check what was done to test.jpg and act accordingly.

If I understood that right, you can do what I do in one of my apps, which is to monitor the computer processes through a timer with

ps aux and parse the result to see when the process starts and when it ends.

You mention the user may save the file elsewhere, I believe the command find can locate it in such a case.

Have I understood right ?

On OS X open -W will wait to return until the app that it ran exits

On Windows

should behave the same

Doesn’t Preview.app quit once all the windows are closed?

Open and start wait until the app designated to open / edit them quits
And both you can start a new instance of the app even if one is already running - so you can be sure when that one quits it was the one you started.
What you cannot easily tell is if the person opened another file & closed the one you started the process with.
Well you might be able to monitor busy files and such using OS event handling - on OS X FS Events not sure about Windows.
Then you could tell when / if the file you started the app with was still in use - thats really what you want to know.

On OS X this is more likely a Kernel Queue
https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/KernelQueues/KernelQueues.html#//apple_ref/doc/uid/TP40005289-CH5-SW2

I did not understand you wanted to kill the process. Just that you wanted to know when the user has quit the app you launched.

Even monitoring busy files, how can you tell the user is really finished using the launched app unless he quits ?

Frankly I would not dare closing another app on the user without first asking politely permission with a dialog.

On a Mac the command to list open files is lsof <PID>. I just fiddled with that for a while. It lists an impressive number of files for a given process down to the most peculiar temporary file and even network connections. BUT it does not list files open for editing for instance in Photoshop or Preview.

Then still with the same test files I tried to see if the system somehow locks them to prevent deletions or moving, or after opening a file from a removable media, if the system does not want to eject because a file is busy. Neither. So it seems that both these apps do not lock the files while they are edited.

I am afraid you are after something that is impossible. When apps do not lock files while they are using them, I see absolutely no way to find out when a user is finished with them. The only thing you can detect reliably is when the process you initiated is terminated (the editing app has been quit).

Thats why open -Wn on OS X might be the best
You can force a new copy of the app to open and edit the file but still all you can tell is that instance ended

Windows has a similar thing but again same problem