Need help with a macro

Oh, ok. Will do that.

I’m hoping to eventually get everything converted from TE to KM since I don’t have Internet @ my office. TE wants to “phone home” too much for my liking and quit working if it can’t connect.
I bought Dave Sparks’ KM Field Guide maybe that will help. At least I can go watch a video when I get stumped which is often.

Did this come into KM right

Or I guess I should have said correctly. Not that it came in on the Right. But I meant correctly.

Took my original apple script and put it in the Script editor and ran it and got this error.

error "System Events got an error: Script Editor is not allowed assistive access." number -1719 from menu bar 1 of process "Word"

The one Griff had when I tried to play it in KM, KM disabled it.

I have my office computer home today, Saturday, to try and get this bloody script to work before it goes back to the office where there is no internet.

I googled that error message and found this solution:

https://discussions.apple.com/thread/253248516?sortBy=best

The key point being, "You need to add Script Editor to the System Preferences > Security & Privacy > Privacy > Accessibility panel"

To be honest, I'm not really understanding the issue here. I just did a quick google for you.

Ok I got my script to run in KM it worked in Word but I need to be able to input my values for ?Title, ?sdat, and ?series. Also when it ran the file remained highlighted. My issue trying to debug through the week on the Office computer without Internet available is next to impossible.
I think once those two things are done it will work and then on to my save macro and others I need to convert.

I tried that. I went into Security & Privacy and Script Editor wasn't listed. When I get the error it doesn't tell me to go to Accessibility or Privacy & Security. When I go there I don't have an option to turn Script Editor on like I usually get. I did get it into KM finally as per above post. I just have to get the the varibles into a user input prompt of some type

In many of the replies here, we've posted actual macros that take actual input for the values and replace them in the document. And @Nige_S' AppleScript demonstrates precisely how to take input from Keyboard Maestro and use those variables in the AppleScript. In particular, this is the bit that takes the KM variables and turns them into AppleScript variables:

All of the questions you ask have been answered here, sometimes many times over.

Yes, and that's the problem: You need to add it by clicking the "+" sign at the bottom of the window:

.

What does that mean, remained highlighted?

-rob.

Sorry. When they were answered I didn't have access to the office computer. Get to the office and didn't have the Internet to go look at that answer. Sorry. I guess I should have given you my email.

Ok my script starts out with highlight the document text. Getting ready to do the search and replace. Then it looks for the ?Title, ?Sdat, and ?series variables. replacing what has been inputed for them for this document. I thought the user input prompt was in my original script. So when I ran it I did its replacement with blank since no input had been given. But when it finished it kept the text highlighted. I have to figure out an un highlight command. Oh, there is no + in Accessibility or Privacy Security for me to add Script Editor.

What version of macOS are you on?

-rob.

Sonoma 14.3

System Settings > Privacy & Security > Accessibility. That's where you look, and you should actually see Script Editor in the list already; toggle it on. If you don't, use the plus sign at the bottom.

-rob.

Ok Rob is this right?

--- 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
Set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set theTitle to getvarible "Local_Title" instance inst
set theDate to getvariable "Loal_Date" instance inst
set theSeries to getvariable "Local Series" instance inst
end tell
tell application "Microsoft 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 "%>"

I tested in Script editor and it told me Expected end of line but found ""

You have a typo here:

set theTitle to getvarible "Local_Title" instance inst

You're missing the 'a' in getvariable. With that change made, the code compiles. But just looking at it, I don't think it's going to do anything. For example:

	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

You're telling Word to find the text ?Title and replace it with ... absolutely nothing? I think you want those lines to read:

	tell myFind
		execute find find text "?Title" replace with theTitle replace replace all
		execute find find text "?Series" replace with theSeries replace replace all
		execute find find text "?sdat" replace with theDate replace replace all
	end tell

And the same issue is in the footer replacement:

execute find find text "?Title" replace with "" replace replace all

That should probably be:

execute find find text "?Title" replace with theTitle replace replace all

Note: I edited your post to use the code posting shortcut in the forum: When posting AppleScript, type three single quotes at the start of a new line, then type AppleScript. Press Return and then paste your code. On a new blank line, put three more single quotes in a row to end the code block. Like this:



-rob.

Thank you sir. That got me back to the accessibility error. Always tell my students we are all ignorant in different areas. Some more than others.

That is where the information I am prompted to put in for ?Title or ?sdat or ?Series would go. If that gets replaced it will not be blank. I am currently getting blank info in those areas. I think because I don't have the user prompt written correctly.

Hard to get my head out of C# at times.

Can you please post the entire macro you are trying to run? Select the macro in the editor, then use the Share button and select Keyboard Maestro Forum to do so.

-rob.

Well do when I get back to the computer