Save as or Export to ... a different folder actions makes frequently used macro slow and less reliable


My question and the attached macro concern exporting all notes in the Bear app, but this is basically irrelevant. It concerns all apps which have an "save as" or "export" or "backup" menu items where the user wants to save or export to either confirm that the destination folder is correct or save to an alternative folder. I have many macros which contain this routine. Bear is just one of many. I suspect that this may be a common issue for forum members.

The macro below works fine but there is a marked slowdown at the point where I define the directory. Pauses have to be long (6 seconds total), and the macro sometimes fails. Attempts at shorter pauses simply increase the fail rate.

Is there an alternative, fast and reliable way to rewrite this section the macro from type ⇧⌃G to press ↵ as shown below?

thanks in advance for your time and help

ZZ Test Backup ALL Bear Notes.kmmacros (28.8 KB)

difficult section of the macro (click to expand/collapse)

the complete maco (click to expand/collapse)

You're at the mercy of your OS and its attempts to resolve the path -- you might have better luck if you insert by pasting instead of typing, since it then won't try to re-resolve with every character typed.

You might be able to change the first phase to a "Pause until... image found in front window" -- this:

...the "Cancel" button at the end of the "Go to" text field, works for me.

Another option would be to install/use Default Folder X. I don't have it but have heard it's very AppleScriptable -- instead doing the ⇧⌘G routine you should be able to tell it to go straight to the appropriate folder.

1 Like

I ran into this with MacroBackerUpper, and struggled with it for a while. Found Image worked, at least on my Mac, but I worried about portability to others (different display settings, resolutions, night mode, etc.). So after some experimentation, I came up with this:

The Save button becomes disabled when the Go To Folder path input screen is fully loaded. This was the best solution I came up with, and it's been 100% reliable.

This also came up in MacroBackerUpper, as one user just could not get the macro to work. It turns out that the work DefaultFolder does to wrap their UI around the Save window was causing issues when I tried to interact with it.

I tried to work around it, but in the end, the only solution I found that worked was to disable DefaultFolder while the backup macro was doing its exporting, and then enable it once that was done:

I don't recall exactly what the problem was, other than when Default Folder was running, the export step never ever worked.



Oooh! Good spot!

Nice. I do wonder what the "interference" was, though -- I was thinking you might avoid any KM interaction with the dialog at all by using DFX.

Time to page @noisneil, I know he's done a lot with KM and Default Folder X.

1 Like

I don't know enough about DFX to answer that, but for a personal macro, it's probably possible to use it to avoid the dialog. My comment was supposed to be more general about how having DFX installed may cause interaction issues with the Open/Save/Export dialog in various macros until/unless you know why it's happening.

I went back to my messages and found my DFX conversation with the tester, and the problem is that when DFX is running, it seemed I had to insert an extra Tab keystroke to get to the text input line in the Go to Folder dialog. Then I could type (paste) the path.

I could have coded that, I suppose, but I don't like coding around things I don't own or use, as if they happen to change something, the macro would break. And DFX has good AppleScript support, so it was really easy to disable before I show the Export dialog, and re-enable once that's done.


1 Like

thank you @Nige_S and @griffman

  • default folder X
    it's not practical in my case because the same macros always change to the same folder. I do not want to navigate default folder X each time.
    But there is another issue which bothers me and caused me to put default folder X on the sidelines.
    default folder X updates are extremely frequent, much much more so than any other app I have worked with. Can be weekly. Is that something that would concern either of you ?

  • the question I posted.
    In the meantime, I asked chatGPT which came up with the following script which I thought would work. A very fast (no delays) and elegant solution.
    Note that the filename is ZZ Test Pages.pages
    Instead it created a file the following file: ~/DesktopZZ Test Pages.pages. Note that the file is in the home (not desktop) folder and the script concatenated filename and folder.

tell application "Pages"
	-- Ensure there's an open document
	if (count of documents) > 0 then
		set theDoc to front document
		-- Specify the path to the new folder
		set newFolder to "/Users/ronald/Desktop"
		-- Get the document's name
		set docName to name of theDoc
		-- Construct the new file path
		set newFilePath to newFolder & docName
		-- Save the document to the new location
		save theDoc in POSIX file newFilePath
		display dialog "No document is currently open."
	end if
end tell

Unless I'm missing something, ChatGPT is missing a slash :). Neither newFilePath nor docName contain a slash, so the above command comes out like this:

set newFilePath to /Users/ronald/DesktopZZ Test Pages.pages

So that's why you got what you got. Add a slash to the end of newFolder and it should work.


1 Like

thank you.
this is what I wrote (added the / after newFolder)

set newFilePath to newFolder/ & docName

and this is the error code now generated (I had no AppleScript error previously)

2024-05-16 14:55:16 Execute an AppleScript failed with script error: text-script: execution error: {} doesn’t match the parameters {input, parameters} for run. (-1721). Macro “ZZ Pages Save All alias” cancelled (while executing Execute AppleScript).

Sorry, I meant like this:

set newFolder to "/Users/ronald/Desktop/"

Leave the rest of the script unchanged from the first version.


1 Like

This works great. The only drawback is that if you intend to share your macro, you might want to add a condition that uses this only if DFX is running; otherwise it uses an AppleScript version.

1 Like

You wouldn't -- the point is that you'd use AppleScript to tell Default Folder the path, rather than trying to macro the "Go to folder..." dialog.

But if @griffman's suggestions fix your problem (and I suspect they will) we don't even need to go there...

Not in the slightest. DFX works a low level, so any OS open/save API or dialog changes might require an update. It also has to work round all the idiosyncratic ways that apps can modify those dialogs too. Frequent updates are a good thing here -- they are very, very likely to update DFX before you've updated to whatever caused them to issue an update!

Or even...

	tell application "Pages" to save document 1 in POSIX file ("/Users/ronald/Desktop/" & name of document 1)
on error errMsg
	display dialog errMsg
end try

...and while I'm not going to take issue with ChatGPT separating out the steps to make things more readable, it's a shame about the missing /.

But the real message here is that if you can AppleScript an app directly, do so and save a lot of heartache. Most AS-able apps will follow the same pattern of "construct a file path, tell app to save document in file path" so you can use what you've got here as a template.


thank you @Nige_S @griffman @noisneil !

1 Like