Using {} Escape Characters in the action script

Different ways to escape the {} characters.
It might be my environment, or maybe I missed something when reading and searching for this, or I’m just a newbee.
Working on a different project a while back, I got a glimpse of this in a post about dealing with the uninstall reg keys that have {} in the reg path, they said to only escape the first one which worked fine. Now I am working on a DoPDF uninstall, trying to check and see if the file exists then run the uninstall command in the cache folder that has folder names that are incased in {}, had trouble getting it to work, then found this bigfixMe post: Issues with Action Script where file path contains { }
where he talks a little about it. needing double }} on the closing side of the folder name. So when I put double }} only on the closing side it worked.
just wanted to make this info more available to people searching for this.

notice the double {{ in the if statement, but on the line to run the uninstall command it uses double }} in the path.

//Uninstall DoPDF 8.9.854
if {exists keys whose(exists (it as string as trimmed string) whose(it starts with “doPDF 9”) of value “DisplayName” of it AND “8.9.854” = (it as string as version) of value “DisplayVersion” of it) of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of (x64 registries;x32 registries)}
if {exists file “C:\ProgramData\Package Cache{fef92eb6-78fb-4a76-a6d8-4bda96483b31}}\novapdf.exe”}
waithidden “C:\ProgramData\Package Cache{{fef92eb6-78fb-4a76-a6d8-4bda96483b31}\novapdf.exe” /uninstall /quiet
endif
endif

also if I remember correctly, in the run.bat, if you have a command line that has a URL that has {} in it, you do not have to escape them.

I hope I’m not wrong, and hope this helps someone else.

3 Likes

That’s right…the two basic rules are:

  • If you are not inside a relevance substitution, and you want to use the { character as a literal without starting a new relevance substitution, escape it as {{

  • If you are inside a relevance substitution, and you want to use the } as a literal without ending the substitution, escape it as }}

This leads to two corrolaries -

  • If you are already inside a relevance substitution, you can use { as a literal without escaping it.
  • If you are not inside a relevance substitution, you can use } as a literal without escaping it.

Two lines of your example show all of the cases -

if {exists file “C:\ProgramData\Package Cache{fef92eb6-78fb-4a76-a6d8-4bda96483b31}}\novapdf.exe”}

Here, you do not need to escape “Cache{fef92eb6” because you are inside a substitution, so { has no special meaning. You do need to escape the } in 4bda96483b31}}\novapdf.exe to prevent it from closing the substitution prematurely.

waithidden “C:\ProgramData\Package Cache{{fef92eb6-78fb-4a76-a6d8-4bda96483b31}\novapdf.exe” /uninstall /quiet

Here, you had to escape the { as “Cache{{fef92eb6-” to prevent it from beginning a relevance substitution, but did not have to escape the } in 4bda96483b31}\novapdf.exe because it was not inside a relevance substitution so } had no special meaning.

4 Likes