The attached macro runs Terminal to delete files in Downloads (chess games I've played). It quits the Terminal but fails to delete the files. If I remove the Quit action, the files are deleted, but the Terminal window remains open. I haven't found a way to make both actions execute.
Thanks for the suggestion, but adding another pause and quit doesn't do anything. The first Quit executes, but the rm command does not (same as before).
Try using an "Execute Shell Script" action instead, putting your command in that -- the macro will then delay until the script step completes which (unless you've set it to "asynchronous") will be after the file deletion has completed:
Also worth noting that the "Delete File" action has a "Delete" option which similarly completely deletes a file without warnings and without using the Trash. So you could keep the whole process within KM, without the "Execute Shell Script" step, by creating a file Collection then doing For Each on that.
Well, my suggestion was based on the usual operation of the command line (terminal) where a command needs to be followed by a return for it to be acted upon. If there is something else happening then perhaps someone else can explain.
It didn’t need one until I added Quit (which isn’t a Terminal command). Someone else could offer an explanation, but I don’t know if that will happen after I’ve marked the problem solved.
The Quit action terminates the shell, so if you have a command that is still waiting for a return, it won't run and so the files wouldn't be deleted.
As for why it worked for you before you added the Quit action I can't explain because when I run your macro without the Quit action, terminal just sits there waiting for me to type return.
BTW - this post is evidence that something marked solved can still be contributed to.
It can, but you’re responding to my responses to you, not to an unsolved problem. When I run the macro (without Quit), Terminal deletes the files and waits for me to close it. I’ll post a video later.
Anyone can respond to any post at any time provided the thread has not been locked - and this discussion is most certainly not locked!
In which case you already have a return character at the end of what your macro is typing into terminal. To make sure I’m wrong about this, please can you post the actual macro that works (I.e. without the Quit) so I can have a look?
Anyone can, but will they, if they see "solved" in the original entry?
I didn't realize it, but I had a physical return in the box (not a return character at the end of the line) ... and now we have an explanation! Thank you.
I do sometimes find myself wishing KM text boxes had the equivalent of "Show invisibles", to make these things easier to spot...
Nice that the problem is solved, but I'd still urge you to do this as an "Execute Script" action instead of within Terminal -- you'll get rid of the needless pauses and remove the chance (however slim, in this case) of Terminal being told to Quit before your command has completed. As an example, try the following (don't worry, du is totally non-destructive, we're simply trying to get the disk space used by your home folder):
As shown earlier, it's the "Execute a Shell Script" action.
You already know enough to do what you need -- you're typing it into Terminal!
"Execute a Shell Script" is almost the same as as "Launch Terminal, type in the command, remember to press the Return key, wait for the command to complete, Quit Terminal". The action defaults to using the bash shell while you are probably using zsh in Terminal, the "shell environment" will be slightly different, and it's less easy to interact with the command (eg to type in a password), but most of these differences can be overcome. And most of the time they aren't important -- commands provided with your OS (rm, ls, and a whole host more) run the same regardless. It's only when you start installing your own packages that things like $PATH matter, and if you're doing that you probably know enough to cope.
The benefits are that you don't have to launch and manipulate another application, don't have to mess with "Pause" actions, don't have to deploy fancy "wait" conditions to make sure the process completes before your macro continues, that you can use the results of the shell command later in the macro, and probably more!
If you are already using a shell via Terminal it's a very short step to using the "Execute a Shell Script" action in KM, and you'll open up a world of possibilities...