Hi All,
Trying to do something which is relatively ‘advanced’ (for me) and not sure if I’m going about it the right way. The background is that I want to quickly scan a large volume of documents into a single folder, and then open/preview each, rename, and (potentially later) move them into a set of folders.
I was hoping to use the ‘for each’ functionality to do this, but as I began working with it I’m not so sure. It seems to fire all actions at once for all files in the collection, where I’d rather step through them. Is this even possible? Different function?
Also failing at the first hurdle as the ‘open using default application’ doesn’t seem to do anything. In my case these are PDF files, so I would expect each to open in Preview. I’ve tested that I’m correctly getting the path but opening a window containing the path for each, so that bit is correct.
Thanks for any help! ![:smile: :smile:](https://forum.keyboardmaestro.com/images/emoji/apple/smile.png?v=5)
Tom
Hey Tom,
What I've done is broken this task down into 2 macros.
The first macro gets a list of paths from the designated folder and places them in a KM variable.
The second macro opens the paths from the variable 1 at a time on each activation and strips the top path from the stack in the variable.
There are ways this could be done with one macro, but these should give you some pointers.
-Chris
Set Variable to Paths of Items in a Given Folder.kmmacros (5.1 KB)
![](https://forum.keyboardmaestro.com/uploads/default/original/2X/c/c25493b30d49d4dbc5c286e91c1690e68c99f5b5.png)
Open Paths from Variable in Default App 1 at a Time.kmmacros (2.4 KB)
![](https://forum.keyboardmaestro.com/uploads/default/original/2X/6/6a3af7d969783a3d6708d2fff399a35d1503d54a.png)
1 Like
Thanks Chris. I’ve downloaded and placed into KM, modified the first script with the path on my local machine. The first run crashed KM. Subsequent runs seem to do nothing at all. Is there some way to figure out what’s going wrong?
Thanks again for the help. The approach you’ve suggested seems sound - certainly an excellent starting point.
Managed to progress a bit. I can see the variable being cleared and populated with my list of files. It’s only the ‘display text in window’ that doesn’t work. Not sure if this is a bug in KM or something else.
Can’t see anything relevant in the engine.log either…
Hi Chris,
Managed to get even further, and the second script (move/rename) is now working quite well. Question is, how do I go the next step and modify the script to iterate through all files until all have been processed. If I use ‘For each’ will this iterate through, or attempt to fire for every file in the folder at once?
Scrap that - I’ve figured it out using ‘For each’. It’s all working really well. Thanks again for your help.