Find a Specific Folder on “Save” Window in cooperation with Default Folder X

ADD-ON: the functioning macro is in post 33.


It's not exactly easy to see where the problem is in this macro. (I tried)

(It's an alternative to the unreliable "Go to Folder" (⇧⌘G) version:
Find a Specific Folder on "Save" Window - #45 by okn )
(for a shortcut to automatically show a certain folder when saving a new file.
Post 19 has the DFX action)

4c Go To Folder to Save File - added Substring + Paste - w- DFX.kmmacros (13 KB)

Your macro worked here on KM v11.1.1, Golden Gate.

You are copying a title value to a variable and appending the
current date.

You are also setting a variable to a folder path.

You import the folder path variable in an AppleScript where you set the parameter of the DefaultFolderX SwitchToFolder command to its value.

However, I think DFX's SwitchToFolder command sends a message to the Save dialog that is front.

Is one open and front when the AppleScript runs?

If you need to wait for one to come front you can use the DFX IsDialogOpen command.

set dialogIsOpen to false
--wait up to 2 seconds
tell application id "com.stclairsoft.DefaultFolderX5"
	repeat 10 times
		set dialogIsOpen to IsDialogOpen
		if dialogIsOpen then exit repeat
		delay 0.2
	end repeat
end tell

if dialogIsOpen is false then return "a save as dialog is not front"

-- place your DFX script below

It looks like you're using paste to set the value of the FilenameField textfield.

To ensure that the textfield can receive keyboard input--or paste-DFX has the SelectSaveName command.

Optionally, you can use DFX's SetSaveName "file name" to set the value, so that the file name text field need not have focus.

tell application id "com.stclairsoft.DefaultFolderX5"
        SelectSaveName
	--SetSaveName "a file name"
end tell

The path in your macro doesn't have a tilde to expand, but it's harmless to use Filter action's Expand Tilde in Path.

Be sure to browse DefaultFolderX's Scripting Dictionary.

It has lots of commands for automating it.

Here's a sample macro that first creates a new TextEdit document, pastes some text, types ⌘ + s to call up the Save dialog.

It then uses DFX's commands to wait for the Save dialog, set the file name textfield and the save destination to ~/Downloads using values from KM variables.

Image

Set the destination and file name in Save Dialog with DFX.kmmacros (5.9 KB)

Hi CRLF, I really wish to look at your macro, but (as it happened before), I cannot even find it, not with SEARCH: "set the dest", or "Downloads".
(And there are ≈ 60 groups in my KM Groups list.)
/

Look in your "Global Macro Group".

But an obvious difference is that @CRLF's macro includes an Action to open a Save/Save As... dialog box, but your macro doesn't. Are you running your macro when the dialog is already open?

No, the dialog is not open, as in the original macro, this heavy lifting is for the macro to accomplish.
And here we have the problem with an unreliable ⇧ ⌘ G.
/okn

Maybe the macro is too fast.
It stops at the Finder dialogue, with Save not selected, ( button is grey).

  • increased the delay in the AScr. from 0.6 to 1.6 but it didn't help.

What do you find unreliable about it? I use it in a lot of my macros, and haven't ever had an issue with it.

There are issues if a user is using Default Folder X and that dialog, but that's the only thing I've ever run into.

-rob.

Hi okn,

It looks like you found the sample macro in the Global Macro Group--which is where your upload also opens to.

Huh.

Here the Save Button only displays as grey if the destination is unreachable, such as a folder on a network volume that is offline--not because of a timing issue.

If the Save button really is functional, try (reverse) tabbing to it from the file name textfield.

Make sure the file name textfield is focused with:
image
Then do:

image

Add more tabbing as needed--on my setup 3 reverse tabs are required.

As @griffman suggests DFX itself might have something to do with keyboard input focus issues.

Here, in the TextEdit Save dialog, ⌘⇧G works only if I manually press it twice (but not necessarily using a Type action). The issue disappears when I quit DFX.

In other programs ⌘⇧G seems to work normally with DFX running.

As for DFX's SwitchToFolder command, just remember it requires an open/save dialog.

Open a save dialog and run your macro. You should find that it works.

The action that performs this, as @Nige_S points out, is the "Type the ⌘S Keystroke to TextEdit" action.

In macros I create to share here, I disable DFX before showing the ⇧⌘G dialog:

When I'm done, if the instance_DFXrunning variable is true, I run the same AppleScript as in the screenshot above, except with Enable instead of Disable.

I was very happy when I found that the DFX developers had included an easy way to disable and enable the app via AppleScript.

-rob.

Good for you ! :slight_smile:

Other users (incl our @Leader) have reported problems with "Go to Folder" (⇧⌘G)

Just to clarify, Leader is simply a title here—notice that I'm one as well. @peternlewis is the developer of Keyboard Maestro.

As for the problems, do you use Default Folder X? If so, that definitely causes issues. If not, then I don't know what's going on, but it's definitely not universal. My MacroBackerUpper macro is quite popular, and the only issues around ⇧⌘G were reported by Default Folder X users, which led to the workaround I posted above.

Sorry you're having troubles with it; it's frustrating when things that should work don't work.

-rob.

DFX also has a number of non-AppleScript actions available as customizable hotkeys.

Go to DFX settings and click the Shortcuts tab.

Find the File Dialog Actions.

Find the Show/Hide Toolbar action and record an hotkey.

Now, in KM just before you run the Type ⌘⇧G action, run a Type action using the hotkey that you assigned to the Show/Hide Toolbar action. The DFX overlay should hide.

I find that once that the overlay is hidden, only the normal single Type ⌘⇧G action is needed to bring up the Go To dialog in TextEdit.

(If you need the overlay, just toggle it back on with another Show/Hide Toolbar hotkey.)

It may resolve other keyboard input focus issues too. :crossed_fingers:

Note that @noisneil is also (IIRC) a Default Folder X user...

Try disabling DFX, as demoed by @griffman, and see if that helps.

…so no DFX AScr. is needed, correct?

So I ran the 4a2 macro below and it did work twice,
and then it got stuck again.

The more recent macro with the DFX AppleScript set dialogIsOpen to IsDialogOpen does not have the ⌘⇧G action.
So I'm not sure which macro we're referring to.

1st the 4a2 macro

4a2 Go To Folder to Save File - added Substring + Paste - (mE) copy.kmmacros (16 KB)

2nd. the 6b xxx macro

6b xxx Set the destination and file name in Save Dialog with DFX off- on - not set - there was no GoTo action.kmmacros (11 KB)

Why not completely disable Default Folder X while you test? That way, you can either rule it out as the cause or conclude it is the cause.

-rob.

DFX was quit completely.

So I tried it with the older 4a2 macro:
5 trials, all 5 worked!

If I use the toggle

does this mean DFX is not active?

in this case I would add it to 4a2 macro and launch DFX again.

I'm not a DFX user, so I can't answer that. From reading what @CRLF said, though, it worked for him if the DFX overlay was hidden before invoking ⇧⌘G. Alternatively, just run the little "quit DFX" AppleScript immediately before and then after using ⇧⌘G.

-rob.

To summarise:

Now I have 3 versions of the macro:

- macro 4a2 with the toggle - Show / Hide Toolbar (works for now)

- macro 4a3 with quit/ open - (works for now)

- macro 4a4 with Disable/ Enable (the simple version) and it doesn't work.

+

But I cannot replicate the

{ } Handle Default Folder X Execute the following actions section.

This is from DFX but looks like KM?

+

When using quit/ activate (tell application id "com.stclairsoft.DefaultFolderX5" to quit) DFX in macro 4a3, this seems to work for now.
(Hopefully)

The simple
tell application id "com.stclairsoft.DefaultFolderX5" Disable end tell
doesn't seem to work.

It got stuck here (and not the new paste for the title either)

That's why it would be better to use your comprehensive
{ } Handle Default Folder X Execute the following actions version.

/

Hey @CRLF
I wrote something below in post 19, please have look :slight_smile: