Macro lose terminal window after each job execution

Hello,

I have a sub-routine that accepts a list of files. Foreach file received, it launches a terminal window and performs a task. (In this instance, it encodes a file using lame) After completion of the task, the terminal window remains open on my screen.

Sometimes I have as many as 20 files that get encoded, so I have to manually close each window after the job completes.

I'd like to have the window close immediately after completion of each task but I am having a problem getting this to work.

I've tried setting the terminal settings to close after execution but then none of the subsequent windows execute b/c the initial terminal window is closed.

Any suggestions???

If you add the line "exit" to the end of your tasks, then change the default setting for terminal to "Terminal Settings / Profiles / When the Shell Exits / Close the window" then I suspect that will do what you want.

Don't open a terminal window - use the Execute a Shell Script action instead.

1 Like

Sorry for the delayed response on this. I've tried that already and what happens is the terminal window will close before the prior command has completed. It's as if the 2 commands are executed in parallel instead of serially.

Encode Encode and Tag.kmmacros (45.7 KB)

How would I go about doing that? I went ahead and attached the macro. I initially hesitated to attach it because there are other things that have to be setup on the system in order for it to really make any sense to anyone. But the primary issue is in the execution of the last few tasks starting at the "Execute JavaScript for Automation" task.

I dynamically construct the lame encoding command just prior to that task and all the enabled tasks following that perform the file encoding. The task that I am struggling with is where the text is inserted by typing it to the terminal and executing it.

Everything works perfectly except that I cannot find a way that will close the terminal window (ONLY AFTER) the file encoding has completed.

Having the exit 0 after the encoding with the Terminal settings set to close the window, will close the window immediately. This also somehow interferes with the next file to be encoded b/c there is now no terminal window.

If I set the behavior of the terminal window so that it does not close, then there's no issue

Hope the way I am explaining this is making sense.

Just use your script command in an Execute Shell Script action something like this:

NOTE: this won't work as is - you have to

  1. Ensure your KM variables are used properly and
  2. The path to lame and anything else is set correctly.

I strongly recommend you read the KM wiki on shell scripting in order to use this action correctly: action:Execute a Shell Script [Keyboard Maestro Wiki]. There is also a ton of discussion on this forum about using shell scripting and using the KM variable ENV_PATH to set the path correctly in the action.

In your macro you should be able to replace all the actions starting with the Set Script Parameters action with just this one.

1 Like