Sub-routine or numbered variables?

I have made a macro that does some renaming and tidying up of the files in a folder. I would like to apply exactly the same changes to a different folder in the same path. I can see two possible ways to do this, create a macro that passes the two older names in succession as variables to the original macro, running as a subroutine, or create two variables with the pathname and then do a loop of the macro, essentially making it a subroutine within the original macro.

Is either approach to be preferred? Or is one easier for a bit of a beginner to implement?

I hope I have explained the problem sufficiently well.

Thanks

Ummm… not as far as I am concerned. :grinning_face_with_smiling_eyes: Someone else might get it… Otherwise, please post some examples of “before” and “after” states.

Try both. You’ll learn along the way, and at least one solution might work! Oh, and be sure to make extra backups when you’re experimentally renaming files, won’t you.

2 Likes

I wonder what this means – deletions, perhaps ?

Sibling folders with the same parent ?


As @kevinb reminds us – the only really precise and eloquent definition of a change is an example.

2 Likes

I’m sorry. I did not explain the actual changes as I am perfectly happy with the macro I made. It does what I need in the folder called, for example, /user/desktop/alice

Now I would like to make exactly the same changes in the folder called /user/desktop/bob

So yes, sibling folders with the same parent.

Thanks @kevinb I will try both, with dummy files as I tend to do.

1 Like

So the path “/user/desktop/alice” (or the real path which it stands in for in this example) is hard-coded into your macro, and you want to change the macro so that it will work on a second path too.

I would suggest that you might as well change your macro so that it will work with any path that you give it, but either way, a fundamental question is how you tell the macro which path to work on.

Would I be right in guessing that, before you run the macro, you will have opened the relevant folder in the Finder to look at its contents? If so, you might find it convenient to make use of the %FinderInsertionLocation% token:

The %FinderInsertionLocation% token returns insertion location in the Finder, which is usually the path of the front window.

I do not see the relevance of numbered variables. I am guessing, but perhaps you were thinking of choosing from a selection of paths? There are various ways in which that could be done, if required.

Thank you. Currently, yes, /user/desktop/Alice is hardcoded. I want the macro instead to loop through Alice and bob, and maybe eventually carol. So I was thinking of a structure where Alice and bob are two variables (not numbered, as such) and could be passed to the sub-routine or whatever.

I do not need to open the folder to know what is in there as I will already have done that an hour or so previously.

Picking from a list of paths might be a simple and flexible way to proceed.

I’ll have a go at implementing something along those lines tomorrow and either return with my solution or further questions. :grinning_face:

1 Like

Good luck and yes, let us know how you get on.

There are so many ways the task could be approached, according to your needs and preferences.

Yes, if there are ever situations in which you want to leave the folder contents unsorted, according to your discretion, you then have a choice of how to choose! :slight_smile: However, if you can work out what the exact circumstances are in which you will want a set of standard operations to be performed, you might prefer not to have to manually run the macro each time.

If it is appropriate to your needs, you could have your macro look at each of the paths in turn and process them as required. If only a few top-level paths are ever to be checked, and if there is not a huge number of files within each folder, this wouldn’t place any significant strain on your Mac, so you could just let the macro run in the background without any interruption to your other work on your Mac. You might even want to trigger the macro automatically, say by using a periodic trigger or according to some related action that you perform on your macro (just one of many possible examples: adding a file to one of those folders).

Not this.

For that sort of thing you want KM's "For Each" Action -- pop either the full paths or the bits that's different (add the base path later) into a variable, one per line, so you can loop through them with the "For Each".

Here's an example that will move screenshots from each user's Desktop into an "Old Screenshots" directory (also on their Desktop):

Otherwise, I heartily endorse @kevinb's suggestion:

2 Likes