potionfactory/LetsMove

After re-launch, application is no longer the active application

Closed this issue · 1 comments

In my testing, the application is no longer the active application after it relaunches. The best I can figure right now is that this is because it starts running while the old application is running, and that when the old copy resigns its active status the next application down the stack takes focus. A simple hack to fix this is to have the new application wait a couple seconds before launching, like this:

[NSTask launchedTaskWithLaunchPath:@"/bin/bash" arguments:[NSArray arrayWithObjects:@"-c", [NSString stringWithFormat:@"/bin/sleep 2 ; /usr/bin/open "%@"", destinationPath], nil]];

That's a bit of hack though, as it just assumes that 2 seconds is enough for the previous app to finish. Something more correct would likely check for the previous pid still existing in a loop before launching the new copy.

I fixed this using your suggestion. This little guy does the trick:

while [ ps -p %d > /dev/null; echo $? -eq 0 ]; do sleep 0.1; done; /usr/bin/open '%@'