I have a macro which has 3 if/ then conditions.
They should work if file is .wav and the name contains either DX or FX or MX.
For some reason it understands only MX. Why?
The problem was the variable FilePath doesn't contain the correct paths. I don't know why.
When I use the Display text action for the file path variable it shows the path of the file from another folder.
If you display AudioFilePath
, does it have the proper value?
-rob.
It'll be difficult to work out unless you upload your macro -- see instructions here: How to Post/Upload Your Macro to the Forum.
Not only are you using global variables -- which means that if something doesn't get set it still has the value from the last time you ran the macro -- but we can't see from screenshots if you've got an extra Return or similar in one of your strings.
Doh! I see a (possible) issue...
FilePath
is a variable, not a path. So your If
needs to check the variable's state, instead of checking for a filename extension:
This should work (as it did in my testing). I'm sure there's a way to use filename extensions from the path, but I think it has to start with a selection of files in Finder, not a folder ... but I'm not positive, as that's not something I do a lot of.
-rob.
It used to work just today!
All sections tested so far are working as intended.
But you are using globals -- your preferences, where global values are stored, may have got a bit stuck. Try quitting and launching the Keyboard Maestro Engine -- you can do that from KM Editor's File menu.
And generally speaking, you should be using local or instance variables, unless you need a global.
https://wiki.keyboardmaestro.com/manual/Variables
Both local and instance variables will vanish after your macros finish; globals stick around forever until deleted. My advice would be to start using locals everywhere, until you run into a situation where you need an instance variable (generally when calling one macro from within another, and you need a variable's value to move to the other macro). When you find you need to keep some variable value around forever, make that a global.
I have about two dozen global variables, nearly all of which are used to hold paths used by various macros. A couple hold some values. But I try to keep everything local, as it makes debugging much simpler.
-rob.
I am sorry for a silly question but can you point me to those globals in my macro?
Any variable that doesn't begin with local
or instance
is a global variable. If you open your settings and go to the Variables tab, you'll see them all.
-rob.
Should I just add local to the variable name to make it local?
Yes, and you can use anything you like between local
and the variable name, and case doesn't matter. As long as the variable begins with local
, it will be a local variable. I personally use local_varName
, but it's completely up to you.
-rob.
Yes: Anywhere you use a variable can be local, instance, or global.
-rob.
I'll try to transform the macro this way and let you know.
EDIT! Sorry. The first point is the silly mistake! I didn't include the variable
- It didn't help so I have created the simple macro which display the text of the items in the selected folder. It returns empty windows
- When I add local to the FinderSelection variable it stopped working so I assume there are some variables that can't be local?
Any variable can have any scope, so that's not the problem. Can you post the simple macro?
-rob.