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:
Ask for the filename you want to use in a Prompt for User Input, save the result to a variable.
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.
Macro selects File > Save As.
Macro types Shift-Command-G.
Macro pastes the variable you created in Step 2.
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.
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.
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:
Ask for the filename you want to use in a Prompt for User Input, save the result to a variable.
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.
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.)
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 ?
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.
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
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
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 ( ) 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.
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