Need help with a macro

When I type ?asTitle I get

If this uploads you see my template above with my file in document an applescript below. I type ?asTitle and get the fillin when I hit ok it replaces the ?Title, ?sdate, and ?series with the correct information.

image

Have you actually tried the macro in this post? It should do what you want, although it may not change the footers -- that can be easily fixed -- and the date may not be formatted as you want to -- again, easily fixed.

Try that, and let us know what needs changing. If it doesn't work, tell us how it doesn't work. That will give us all a base-line that will help us help you -- at the moment, we're shooting in the dark at a target that keeps moving...

Question should the name of the variables match what is in the template? I get this error

CleanShot 2024-05-02 at 07.41.46

That's nothing to do with the macro, and everything to do with Word's spell check. You can either "Add" those items to your dictionary so they're no longer flagged or just hit the "Cancel" button for now.

Ran it again with a trigger of FN COMMAND O and all it did was return me another copy of the template. with small margins over to the left Ran again just got same thing.

?asTitle is my trigger to run the AppleScript. It needs to have a trigger that prompts me to enter the Title, date and series and replace in the template file either in Word or Pages the place holders ?Title, ?sdat, and ?series and in the footer as well.

(Attachment mysermontemplate.docx is missing)

Archive.zip (1006.3 KB)
image

KM wouldn't let me setup ?asTitle as a trigger. I couldn't use any trigger with a "?" in front of it. I wondered on the Fill Word Template from prompt KM from griffman why it didn't run the and do a replace the variables. When it ran all it did was return the file to me and no changes.

It would only work if you used it with the demo file I sent, not your file. Did you try it in that?

-rob.

Yes I did

Some how the first part of the applescript had been left out.

IMG_0161

I know it says Pages at top but doesn't work in pages. I never got it to work in Pages. Where I actually wanted it. But since I got it to go then in Word I gave up. Too many "irons in the fire". I do want to get both to work in Keyboard Maestro. Don't have to take the computer to the internet every day then.

Don't get ahead of yourself -- make sure the macro works from the Keyboard Maestro Editor before you set up a hotkey trigger (you'll also have to remember to remove the trigger from your TextExpander setup).

If you are using my macro, all you have to do is:

  1. Open the Word template, making sure it is the frontmost document
  2. Switch to Keyboard Maestro and select the macro
  3. Click the "Run" button

You should then get a prompt where you can fill in the data you want to use and, when you click "OK", Word will come to the front and the text replacements will happen.

Do remember that Keyboard Maestro is not TextExpander -- in KM you would set up ?asTitle as a "Typed string trigger", not a "Hot Key Trigger", if you still want to use the same keystrokes to fire it.

In km it wouldn’t take ? As part of the trigger.

I understand. I could get yours to work. I just makes me anothe copy of the file with very narrow l/r margins

Works fine here:

image

I imagine TextExpander might be capturing your trigger? Maybe best to disable TextExpander while you're working on the macro.

-rob.

Then you couldn't get mine to work -- on my machine it behaves exactly as you wanted.

It sounds like you have something else going on here. Try creating a new, empty, Word document, pasting in the following:

?Title is the title.

Date is ?sdat.

And the series is ?series.

...and then running the macro. Does it replace the text in Word as expected?

I tried to put the ?asTitle trigger into KM. It would take but the first Character. It put in / instead of ? and would not take any more characters.

Because you are trying to add it as an "hotkey" trigger:

image

...when you should be using a "typed string" trigger: