converting strings to AS code

Here’s a tricky one (at least, it seems tricky to me):

I am loading preferences from a text file into a script property. Some of what is being loaded is strings, but some of these strings represent AppleScript “phrases” like: “ASCII character (44) & ASCII character (46)”.

I am able to load these into the property as labelled parameters with no problem, but I can’t figure out how to coerce them from strings to AppleScript code so that, for instance, I could set Microsoft Word to search for a comma followed by a period (which is what the “phrase” above specifies).

How do I turn “ASCII character (44) & ASCII character (46)” into ASCII character (44) & ASCII character (46)?

(I hope this makes sense.)



Hi Larry.

The run script command is what you’re looking for:

set string_spec to "ASCII character 44 &  ASCII character 46"
set actual_string to run script string_spec

Ah ha! I suspected it might have something to do with interpreting the string as a script, but I wasn’t sure how to go about it. The interesting thing is this construction:

set actual_string to run script string_spec

So, how do I use that? If I set the find object of an MS Word object (like the selection) to actual_string and then execute the find, does AS interpret the “string” for Word, allowing it to search for ASCII character(foo)?

Thanks, kai. There are SO many subtleties!


Exactly, Larry “ so something like this should find the next occurrence of “,.” (ASCII characters 44 & 46) in Word’s active document:

set string_spec to "(ASCII character 44) & (ASCII character 46)"
set actual_string to run script string_spec

tell application "Microsoft Word"
	set selFind to find object of selection
	set content of selFind to actual_string
	execute find selFind
end tell