Yes, but what application are you doing this in?
Getting, or letting you manually input, the data you want to use is easy -- the tricky bit is "inserting" it into your template, because that bit is very application-dependent.
Yes, but what application are you doing this in?
Getting, or letting you manually input, the data you want to use is easy -- the tricky bit is "inserting" it into your template, because that bit is very application-dependent.
Right now I use an app called Text Expander to trigger all this action. I want to switch it to Keyboard Maestro. Main reason is Text Expander wants to "phone iHOME" too much. I dont have internet access at the office. If I can get everything over to KBM I will be better off. The macro works fine at the house. But the office no. I have to bring the computer HOME get it online hope I don't have to reboot at the office or I lose connection to TE. I also would be able to drop a "ransom" subscription each year.
Is that an actual Word form letter form, or is it just a Word document with your specially-coded text in place? If the latter, then I think @peternlewis has the best suggestion:
Just use Prompt for User Input to collect each of the values you need, saving each in a local_theTitle
(or whatever name you prefer) variable. Then you'd need to use Word's Find and Replace feature to search multiple times, once for each template value.
I took a few minutes to cobble together a functional demo:
I will warn you, however, that this is very janky—Word is quite slow with the replace all stuff, and I had to insert timing delays in many places to make it work. If you'd like to try it, here's the macro:
app-Word form replacements Macros.kmmacros (11 KB)
This macro group consists of two macros: One that gathers input, and the other that interacts with Word. I wrote it this way so the Word stuff only had to be written one time. All the Word commands are in a subroutine, and it takes two things as input: The code word and its replacement value.
Here's the demo word document you can test it with:
word form demo.zip (11.4 KB)
If you try to use this yourself, you'll have to add additional subroutine calls (with the delay between each) for each code value you want to replace. But this is probably not the best way to do this, given how really horrible Word seems about wanting to do these things. In fact, it's worse than it looks in the demo, because every time you do a replacement, you have to get rid of this dialog box, too:
It was appearing outside my recorded area in the GIF, so you don't see it, but there's a keystroke in the macro just to get rid of it.
But really, I wouldn't recommend using my macro—it will probably take some timing tweaks to even make it work, and it seems quite likely to break if the speed of the computer is different at a given time when it's launched.
I think a much better solution would be to put the text itself into Keyboard Maestro, where you could then do lightning-fast find-and-replace actions. You could even format it with either Markdown code or HTML, then send that output to an editor capable of handling one of those forms, so it appeared with your formatting.
There may be other approaches along these lines that work well, but if you can take Word out of the picture somehow, I think it's possible to write a much better (and much simpler!) macro than what you see here.
-rob.
And here's a version that works with Pages instead of Word. Pages' main advantage is that the Find/Replace dialog just appears onscreen, and you can use it over and over without having to remove a dialog each time.
I still had to slow things down a bit, but this macro runs much quickly (and smoother) than does the Word version, as you can see in the GIF:
Pages - replacement demo Macros.kmmacros (15 KB)
And here's the sample Pages document I used:
Demo Pages.zip (51.8 KB)
I think using Pages, if you can, would work better than Word; this version seems more robust and less likely to fail. It's also much cleaner, without so much stuff going on in the window.
-rob.
I'm wondering if, in the background, TextExpander is actually using an AppleScripted S'n'R in Word. Here's a KM version:
Fill Word Template from Prompt.kmmacros (3.5 KB)
@Macmike -- open up your Word document then fire up the above macro, fill in the form, and see if what you want to happen... happens.
I'd completely forgotten that Office had re-embraced AppleScript! Much better than my solutions!
-rob.
My Text expander one uses an AppleScript. Iwill try and do a copy and put on here.
On my house computer now. Here is the apple script.
--- select all text
tell application "System Events" to tell process "Word"
click menu item "Select All" of menu 1 of menu bar item "Edit" of menu bar 1
end tell
tell application "Word"
set myFind to find object of selection
tell myFind
execute find find text "?Title" replace with "" replace replace all
execute find find text "?Series" replace with "" replace replace all
execute find find text "?sdat" replace with" , " replace replace all
end tell
-- replace footer as well
set findObject to (find object of text object of (get footer of section 1 of document 1 index header footer primary))
tell findObject
execute find find text "?Title" replace with "" replace replace all
end tell
end tell
-- send right arrow key to unselect text
return "%>"
If I could incorporate that into Keyboard Maestro would be good.
This is what I had set up in TE to save my files from the line where I would type the file name to save. I would use ?File to trigger it.
Oops didn't work. It is a lot of chosing from a list involved.
Year Month Sunday AM/PM File Name _-_File Type
-
-
The AppleScript is already in the macro above, you just need to add the "-- replace footer as well" section and it should work.
Yes, Trying to get the applescript triggered from Key Maestro. Is the issue. The file is a Word Template I call asSermonOutline. As lets me know the Applescript place holders are there.
I'm confused; as @peternlewis notes above, you can run the AppleScript you currently have directly in Keyboard Maestro. The only thing you'd need to do is pass in the values, which @Nige_S' macro shows you how to do.
-rob.
Question. Haven’t had time to get back into the macro yet. The execute AppleScript action. Do I put my script in it or in a folder that I put a call to the folder in the action?
You can do either; I can't speak for others, but I try to keep the code directly in the macro, as it's easier to edit and update that way. Look at the macro I posted today for an example:
-rob.
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.
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