Macro to create a new word document in the folder whose path is in the clipboard

What approach should I use to create a new word document in the folder , whose path (path of folder, not file) is in the current system clipboard.

I would have to

  • input to the macro the name I want to give the file
  • attach it to the path in the clipboard
  • save the file using full path

I find the approach using File→Save As →SHIFT CMD G slow and tedious and I am going bananas trying to figure out a solution.

thank you very much

You're going to have to use File > Save As to make the file in Word, so there's no getting around that. But you can automate the Shift-Command-G part. The basic flow would be:

  1. Ask for the filename you want to use in a Prompt for User Input, save the result to a variable.
  2. Append the filename from step 1 to the path from the clipboard and save as a variable. Depending on how the path is saved, you may have to insert a trailing slash before adding the filename.
  3. Macro selects File > Save As.
  4. Macro types Shift-Command-G.
  5. Macro pastes the variable you created in Step 2.
  6. Macro presses Return.

That would let you hit one hot key, type the filename, and be done—assuming the path is already on the clipboard, as you stated.

-rob.

I will try and give you and update. Thank you very much @griffman By the way, I use MacroBackerUpper many times a week. It’s a gem !

If you have any troubles, just post—it should be fairly straightforward, though, which is why I just posted an outline :).

Thanks ... and somewhat ironically, MacroBackerUpper uses Shift-Command-G and a typed path in order to do what it does :).

-rob.

It works (thank you !) but requires 5 seconds of pauses which I wanted to avoid.

I was hoping that shell or apple scripting would help.

Create Word File in Current Forklift Folder 12 Jul 2026 .kmmacros (10.4 KB)

A quick comment from the side, I find pauses of 1 s (or other random times) to be fragile when saving files (or doing other stuff). I therefore tend to use Pause Until which is more reliable (and will reduce the pause time to the bare minimum to execute) and even a few AppleScript based pauses to make sure things are bullet proof.

In a similar case to yours for example, I have an AppleScript that checks that the filepath in the ⌘G sheet matches the fielpath that I am pasting as I have had problems with this in the past. The AppleScript is:

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set expectedPath to getvariable "Local_BackupFilepath" instance kmInst
end tell

tell application "System Events"
	tell process "Keyboard Maestro"
		repeat with w in windows
			try
				if (exists text field 1 of sheet 1 of sheet 1 of w) then
					if (value of text field 1 of sheet 1 of sheet 1 of w) is expectedPath then
						return 1
					else
						return 0
					end if
				end if
			end try
		end repeat
	end tell
end tell
return 0


While the below AppleScript Pause Until the ⌘G sheet actually appears (also something I have had problems with):

tell application "System Events"
	tell process "Keyboard Maestro"
		repeat with w in windows
			try
				if (exists text field 1 of sheet 1 of sheet 1 of w) then return 1
			end try
		end repeat
	end tell
end tell
return 0

Admittedly you may not need any of these but I am sharing because i) they exists and ii) they may avoid future problems similar to those I encountered.

Happy to answer any questions.

I misunderstood your request: I thought you had a Word document open, and wanted to Save As a new name. Do you just need a new blank Word document in some location?

If so, the macro is much simpler:

  1. Ask for the filename you want to use in a Prompt for User Input, save the result to a variable.
  2. Append the filename from step 1 to the path from the clipboard and save as a variable. Depending on how the path is saved, you may have to insert a trailing slash before adding the filename.
  3. Use the Create Unique File action, and put the name of the path/file variable in the first box. (This action also saves the name and path to a variable, which you provide in the second box. You may or may not need this.)

-rob.

great ! thank you very much. I am creating 2 versions, one when I am in the folder, and one if I am working on a document in Word. Do you use Default Folder X ?

thank you for your suggestions. I managed to successfully replace 4/5 1 second pauses with pause until, and the macro does run faster

I don't - my Finder needs are pretty simple, all things considered :).

-rob.

You might find this easier -- it's certainly less resource intensive:

It works because the Action only scans the frontmost window -- the "Save" (and "Open") dialog has a "Cancel" button, the "Go to..." dialog doesn't.

Another way would be to keep a template of the type of blank document you want to create and copy it using it the unique file path as the destination. After that, open the copied template.

@CCStone made such a macro here:

Create a New File in the Finder from a Selection of Templates - #10 by ccstone

I imagine it can be adjusted to include a Word document.

Alternatively, here's an AppleScript that works for me with Word 2016 on Mojave 10.14.6

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

(*
-- Granting permissions to AppleScript to save the new file should not be an issue when this is run in KM's Execute an AppleScript action. 
-- If running this elsewhere pops up a grant permissions window this trick for Excel works with Word:
--
-- https://www.macscripter.net/t/remote-app-asks-to-grant-access-to-every-single-file-i-ask-it-to-open/71613/8

set sd to path to startup disk
try
		close sd -- will error
	end try
*)

set kminstance to system attribute "KMINSTANCE"
tell application id "com.stairways.keyboardmaestro.engine"
	set uniquePath to getvariable "localUniquePath" instance kminstance
end tell

set uniquePath to POSIX file uniquePath as text

tell application id "com.microsoft.Word"
	set newDoc to create new document
	--make new document -- generic command 
	save newDoc in uniquePath
end tell

the problem is that the pause is between the ⇧⌘G and the paste (at which time the cancel button has not appeared yet), not after the paste.

It’s quite a coincidence that you are posting because you taught me a trick in a previous post which seems to work

You can also use AppleScript -- if the frontmost document is not yet saved to disk this will save it, otherwise it will make a new document and save it:

set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set theFilename to getvariable "Local_Name" instance inst
end tell

set thePath to POSIX file (the clipboard) as text
if thePath does not end with ":" then set thePath to thePath & ":"
set thePath to thePath & theFilename

tell application "Microsoft Word"
	try
		if (exists document 1) and (path of document 1 = "") then
			save document 1 in thePath
		else
			set theDoc to make new document
			save theDoc in thePath
			activate theDoc
		end if
	on error
		activate
		display dialog "Save failed -- make sure you are using a unique name"
	end try
end tell

And you could use it in something like this:

Word Saving.kmmacros (5.4 KB)

Yes, that "Pause until Cancel button does not exist" pauses the macro until the "Go to..." box has appeared. You should then be able to "Paste", "Keystroke: Return" then "Pause until Cancel button does exist", which is when the "Go to..." has gone ( :wink: ) and you are back to the "Save" dialog.

There's many ways to do what you want, but they all start with deciding what you want. Do you just want to create a new Word doc in a folder on disk? Use @griffman's "Create Unique File" method. Create then open in Word? The same method followed by an "Open File" Action. Do something in or depending on Word? Then you are going to have to interact with Word in some way.

thank you very much. I created a template as you suggested and simply use the open file action in Yoink. It works perfectly

I will give it a try. Thank you very much !

I have 2 scenarios: I want to insert a blank template and I am in Word and want to save to the path in the clipboard. Both scenarios are now solved, and thanks again very much

Excellent, happy that I was able to help!

Appreciated, I will give it a try!

Thank you!