Weird behavior when typing path

I have a macro that when I'm on a Save As window, it types a certain path. Sometimes this happens:
Screen Shot 2022-04-24 at 2.33.46 PM

Please note that the path should be something simple like this:
/Users/dannywyatt/Backups

I just found this other thread and answer:

Would you confirm that adding the delay of 0.02 could fix this?
Also, it was mentioned that this can be set globally. The way to do this is by adding a macro inside my Global Macro Group and set it to Permanently? Like this:

Thanks!

Wouldn't it be easier to paste in the path instead? Something like:

And you could use a KM variable token if you wanted different paths in different situations.

Unless there's a specific requirement for something to be typed or you want to maintain the current System clipboard contents (and I'm sure there's a workround for that problem), I would think that pasting is generally more reliable.

1 Like

In my experience, ⇧⌘G can be a little temperamental via KM in open/save dialogs. Then again, so can every other method. There isn't a 100% reliable one, at least not for me.

However, @iamdannywyatt doesn't seem to like adding pauses for some reason, so this is a worthy alternative. Honestly, adding pauses isn't that hard. You can save the pause and typing actions as a favourite if you like.

1 Like

@noisneil -- good to know before I do something (even more) stupid!

But, given that @iamdannywyatt's issue is with the text he's subsequently typing into the dialog, is there any reason not to use a paste action there instead? Or is paste similarly flakey in that situation?

You could do that but the path box won't pop up with a paste action. You'd have to either type or simulate "/" or "~" and then paste the remainder of the path.

Side-note: I've also noticed that waiting for and pressing the "Go" button has a slightly better success rate than hitting Enter.

I'm starting to think that my computer is s-o s-l-o-w that other people are seeing timing/keystroke issues that are simply passing me by!

I wonder if a "tell application "System Events" to keystroke "g" using {command down, shift down}" AppleScript action would be any more reliable? Unfortunately, I can't test the latter until I can break the former...

I've tried that and got the same behaviour, but you might be luckier than I was.

Thanks for the replies!

To be honest, I thought that this option was based on the Clipboard so I didn't even bother doing any research. It is indeed a better option and faster (I guess). Thanks for the tip!

I was trying to understand how to use variables and one thing I noticed is that once I set a variable, even if I delete the action containing that variable, when I go to Insert Token, it's still there. How can I delete it?
Also, I was trying to set a global variable by creating a macro with no trigger with just the action to set a variable, but when I try to use it inside another macro, nothing gets pasted. How to set global variables?

What I noticed is that if you type the name of the file and then you use the / keystroke, it will add / to the end of the file name, so to work around that, the macro needs to have a Select All action before the / keystroke action, because / only works when the text is selected. Now with ⇧⌘G (which I will probably be using from now on, it opens the path dialogue regardless of the file name being selected or not, which is a good thing. I will see if I experience any hiccups using it, as you mentioned.

I don't know why you would think that, because I have no reason for adding them or excluding them :slight_smile: As long as the macro works, I add/exclude anything. If at some point I wasn't adding Pauses, was just because in my mind I was thinking it wasn't necessary for the workflow.

I'm a bit confused about this statement, because I just created this macro and it works as expected, without using the / or ~
Screen Shot 2022-04-25 at 4.48.05 PM

Can you please clarify what you mean?

See this bit of the really good manual. Basically, variables are global unless you declare otherwise, and globals persist even over Engine restarts -- set them to "" (an empty string) to clear them.

And pay far more attention to what @noisneil says than to me -- I've read (bits of) the KM manual and futzed about, but @noisneil will have way more experience of how KM behaves in real life!

1 Like

I was just doing some research and it seems that you can actually delete them via the Preferences: manual:Windows [Keyboard Maestro Wiki]

I figure it out when it comes to setting Global Variables. When I set a variable without a trigger, I have to actually run the macro at least once so it registers the variable. It's working now :slight_smile: This is super helpful! Really appreciate you mentioning the variable as text to paste, @Nige_S

If you want the variable to be empty but still present in the Preferences window, then do as @Nige_S says and set it to nothing using a Set Variable to Text action. If you want it actually gone, then:

When variables aren't needed outside of the running macro, it's considered good housekeeping to prefix them with "local__". Example above would become "local__MyVariable". The variable will not persist once the macro has completed its run. (In case it's unclear, the line is two underscores.)

As @Nige_S suggests, check out the manual if you're scratching your head. Oh, and don't pay attention to him saying you should pay more attention to me! :joy:

In order for a variable to be set, the action that creates it must actually be run. For example, a Set Variable to Text action is only an instruction for the KM engine to set the variable to that text. The action must actually run for the variable to be set. You can simply right-click the action and select "Try action" to do this.

When you try to use the variable inside another macro, you will need to format it depending on where it's being used. If you see a V sign beside the text field, it expects a variable and no additional formatting is needed:

Pasted_Image_25_04_2022__17_11

If you see a T, the action expects text, so the example given above will need to be enclosed inside %Variable%_______% and should look like this:

%Variable%MyVariable% (the bold part is the name of your variable)

Open a save dialog. Type the / keystroke. See that it opens the path field box?

I didn't mean that you don't like pauses; I meant that you would prefer not to have to, and for there to be a global delay setting, as you mentioned in your original post. Sorry, my mistake if this isn't the case.

There are a few ways to navigate to a path in a dialog window that I know of:

  • type / or ~ and then the remainder of the path
  • hit ⇧⌘G, type or paste the path
  • simulate ⇧⌘G using AppleScript and enter the path
  • the witchcraft used by Default Folder X, which is proprietary and nobody else seems to know how it's done.

In your screenshot, you've already used the second option, so you don't need the first.

1 Like

So basically:
1 - To make a variable empty (and not available on other macros, but still in the Variables Preferences Pane), set the "to" to "", then hit the Run button at the top.
2 - To completely delete a variable, set the "to" to %Delete%, then hit the Run button at the top.
Correct?

I saw on the manual that local variable should start with "local". I saw you added 2 underscores. Is that required, the 2, or is it just how people use it inside KM as a standard?

Yes, I've been checking some stuff there too. And don't worry, I tend to just read what people say and then test it. If it works, that's what matters :slight_smile:

Yeah, I figured it out a little bit before you replied. It was by accident, actually. I just thought "let me see if I need to hit Run". And it worked :wink:

I was a bit confused about this section, but I guess I understand it now. Basically when I click inside the "Set variable" field, it shows me the V. Then I click inside the "to", it shows me the T.
I will keep using this and see if there are other scenarios where this behaves differently.
Thanks for explaining this!

It does, but what I mean is that sometimes you type the name of the file you are saving and only then you pick the destination folder, so after you type the name if you hit / it will add / to the file name. So for you to go back to being able to hit / to open the path field, you need to hit CMD+A to select all text. Only then will you be able to hit / and open the path box. On the other hand, selected text or not, hitting Shift+CMD+G, will always open the path box, which seems to be more effective for any scenario.

What I meant is that, if adding that delay to actions where typing is involved is good practice to avoid glitches, then I would rather have it set as a global setting instead of adding additional actions at the top of each macro. I have no issues with pauses, if that's what the macro needs. Actually, I've been creating a lot of macros that probably have too many pauses, but... I rather play safe haha.
By the way, I set the global delay, but for some reason it seems that the speed is pretty much the same (or maybe it's still fast, but slow enough to make it work?). Should I increase to another value instead of 0.02?
Is this how you set it?
Screen Shot 2022-04-25 at 5.49.34 PM

With the different behavior I just mentioned that if the whole filename is selected, both options will work. If none of the filename or just a bit of the text is selected, only ⇧⌘G will work.

Anyways, I really appreciate you taking the time to clarify some stuff and sharing some knowledge! :slight_smile:

1 Like

You could also uninstall KM! I was assuming you wanted something a little more user-friendly, eg within a script before doing something that might set it, and then doing a conditional based on whether it was set or not.

1 Like

That seems too radical hahaha

No, I just wanted to be able to click the Insert Token > Variable, and only see the variables that are actually available instead of seeing old variables that are doing nothing and just sitting there.

But going to the Preferences seems to be better, because there you can actually see all variables (old and new).

Nitpick -- even that doesn't delete the variable, it sets the value to "" and hides it in the GUI. You can still access it, for example via AppleScript -- not that it does you much good!

1 Like

No, you only need to not be in a text field (the file name box, tag box, search box, etc). If you're still in the file name field, Shift-Tab will get you out and / or ~ will get the "Go to Folder" dialog up.

1 Like

I used that as an example, because when you open the Save window, it defaults to the filename being selected, so for a macro, you would focus on only adding actions that are necessary instead of adding irrelevant ones. So if the macro starts with the text being selected and let's say you have an action to rename the file you are saving, then you can do:
1 - Rename
2 - Shift+CMD+G

For the workflow you just described you would have an extra action, the Shift+Tab, which becomes irrelevant and something extra that doesn't need to be there in the first place. And I'm all about reducing macros to the bare minimum when possible.