Check with shell if file exists

After I had again fun with missing AppleScript permissions I thought I could add a check if the InfoPlist.strings are written. But I can’t get the Shell script to work.

The location of the file is okay:

But the Shellscript gives me the result of “not okay”:

if [ -f "/Applications/Mail\ Archiver\ X\ 6.1.3.app/Contents/Resources/de.lproj/InfoPlist.strings" ]; then echo "ok"; else echo "not okay"; fi

You could try

ls -a /Applications/Mail\ Archiver\ X\ 6.1.3.app/Contents/Resources/de.lproj/InfoPlist.strings

Then if in shell.result you don’t get a string that contains “InfoPlist.strings” it means the file is not there.

1 Like

Thanks, that works fine.

The reason your original command doesn’t work is that you are both quoting and escaping the path name. If you are using backslashes for spaces in the path, then you would not put it in quotes.

E.g. use one or the other, but not both:

// Escaped form - spaces must be preceeded by backslashes
/Applications/Mail\ Archiver\ X\ 6.1.3.app/Contents/Resources/de.lproj/InfoPlist.strings

or

// Quoted form - spaces are not escaped
"/Applications/Mail Archiver X 6.1.3.app/Contents/Resources/de.lproj/InfoPlist.strings"
2 Likes

That is odd. Why would the following script make 2 prints of the app path?

Dim AppPath As String = CurrentBuildLocation + "/" + ReplaceAll(CurrentBuildAppName, " ", "\ ")
if right(AppPath, 4) <> ".app" then appPath = appPath + ".app"

dim command as String
command = "ls -a " + AppPath + "/Contents/Resources/de.lproj/InfoPlist.strings"
theResult = DoShellCommand(command)

@Mike_D : I tried that, too, and forgot to remove one of the \ which I only saw after starting hard. The problem is that CurrentBuildLocation usually already comes as shell path.

CurrentBuildLocationNative is what you want.

1 Like

Also, I believe you can combine escaped and unescaped paths if you get the quoting right, e.g.
/Path \ to \ my \ app\".app/some subfolder with spaces/" is a legit way to do it, combining the two styles.

1 Like

The CurrentBuildLocationNative worked nicely. I had to fight with the echo for quite some time so it didn’t echo to Xojo with a dialog. Another High Sierra problem probably.

Here is my final solution:

command = "if [ -f """ + CurrentBuildLocationNative + "/" + CurrentBuildAppName + "/Contents/Resources/de.lproj/InfoPlist.strings"" ]; then /bin/echo 'ok'; else /bin/echo 'not okay'; fi"
theResult = DoShellCommand(command)
if inStr(theResult, "not okay") > 0 then
  print "AppleScript permissions missing"
end if
1 Like