Extract name of new file in folder

Hello everybody

I'm looking for a good solution to extract the filename of a newly added file to a folder and put it into a variable.

So far I have found the right tigger for this macro, but I'm having trouble extracting specifically and only the filename of the last added file.

Anybody got a quick fix?

Easy - take a look in the KM wiki here: https://wiki.keyboardmaestro.com/action/Split_Path

Well, the issue is that it does not specifically address the most recent added file, right?

Well, you didn’t say that in your post, right?

Use the Folder trigger as described here: trigger:Folder [Keyboard Maestro Wiki] which will pass the name of the newly-added file in the KM token %TriggerValue% which you can process with the Split Path action.

I hope that’s more helpful. If not, let us know.

Super nice! That opens up a whole lot of new possibilities.

It just so seems that in this specific case, it does not want to work as I imagine.

Seemingly, %TriggerValue% has the correct path stored. Oddly enough, Split Path does not seem to recognise the string.
Any tip?

Alright, I managed to solve my problem by using Filter Variable with File Name, but I still wonder what would make Split Path not work in this case...

Can you upload a screenshot and the relevant macro to see the steps you took to better assist you

1 Like

This works fine for me:
KM 0 2021-06-01_15-24-14

You should note that %TriggerValue% only has a value when the macro is triggered, so if you're just trying the 2 actions you've shown us on their own it will not work.

Please post your full macro as per @hello's request.

1 Like

Yep. Read what the Action is saying:

As @tiffle said:

Thanks to everybody for the replies.
I did try running the full macro when I was troubleshooting. The issue was that I had some space-characters in the file path which were not automatically escaped when entering the file path through the "Select Folder" button.
Split Path did not work with that. Luckily "Variable Filter" works like a charm.

1 Like

I appreciate the thanks, but since you never shared your "full macro" it's hard to understand your comments.

When I use the Choose button in the Split Path action it always works regardless of the spaces in the path. Like this:
KM 0 2021-06-02_09-13-35

I would hate to think that another KM user might read your comments in the future and conclude that the Split Path action doesn't work properly when it plainly does. But of course you might well be referring to something else.

Anyway, glad you found a solution!

Ahh, you are right of course. Here is a screenshot of a test case.

I think I understand it a bit better now. So $TriggerValue$ is only limited to the scope of one iteration of the macro and is cleared after that. Seems like that's the problem why I get the "Not Available in Editor".

Clearly, in this case, it would work then.