Nested if else relevance

The following relevance is failing on Windows because somehow it is trying to process the Mac portion “string “CFBundleVersion” of dictionary of file…” and failing.

 if (name of operating system contains "Mac") then (if not exists file "/Applications/CrashPlan.app/Contents/Info.plist" then "Not Installed" else string "CFBundleVersion" of dictionary of file "/Applications/CrashPlan.app/Contents/Info.plist") else if (name of operating system contains "Win") then version of file "C:\Program Files (x86)\CrashPlan\CrashPlanDesktop.exe" else "N/A"

How would I rewrite this so that it works on both Windows and Macs?

Thanks

I suspect your problem is that you have an error in the Windows part of the statement - such as the executable not exist but the message is showing what is on the error stack.
So you should check for the existence of the file on Windows as well.
I am keeping the structure of your statement and it would be something like this:

if (name of operating system contains "Mac")
then 
   (  if (exists file "/Applications/CrashPlan.app/Contents/Info.plist") 
      then (string "CFBundleVersion" of dictionary of file "/Applications/CrashPlan.app/Contents/Info.plist") 
      else ("Not Installed") )
else 
   (  if (name of operating system contains "Win")
      then ( if (exists file "C:\Program Files (x86)\CrashPlan\CrashPlanDesktop.exe")
             then ((it as string) of version of file "C:\Program Files (x86)\CrashPlan\CrashPlanDesktop.exe")
             else ("Not Installed") )
      else ("N/A") )

Without indents, it would be:

if (name of operating system contains "Mac") then (if (exists file "/Applications/CrashPlan.app/Contents/Info.plist") then (string "CFBundleVersion" of dictionary of file "/Applications/CrashPlan.app/Contents/Info.plist") else ("Not Installed")) else (if (name of operating system contains "Win") then (if (exists file "C:\Program Files (x86)\CrashPlan\CrashPlanDesktop.exe") then ((it as string) of version of file "C:\Program Files (x86)\CrashPlan\CrashPlanDesktop.exe") else ("Not Installed")) else ("N/A"))
2 Likes

First you can use the big shortcuts

windows of operating system
mac of operating system

Second make sure your relevance is in {} not ()

Also it might be possible for you do use the regapp inspector

3 Likes

When writing nested IF THEN ELSE statements, I find it helps my sanity to “preformat” the statement. I start with …

IF () THEN () ELSE ()

Which might then become …

IF (Windows of Operating System) THEN (Blah) ELSE (IF () THEN () ELSE ())

Each section should be wrapped in it’s own parentheses to ensure proper order of execution. Providing the Structure before filling in the “bit” helps keep thing straight for me.

I picked up this habit years ago, and it stuck.

3 Likes

Great to know, thanks!

Ah, I always did this with code, but never thought to do it with relevance. Thanks!

This works, thank you! It looks like it is indeed down to the existence of the file. Thanks again