AnsweredAssumed Answered

How to handle filename quotes in Applescript Do Shell Script ... script step

Question asked by pm125 on Sep 18, 2018
Latest reply on Sep 19, 2018 by steve_ssh

Asking for help on running Unix shell commands from Filemaker on a Mac. Apologies for the complicated and lengthy form of my question. I know there are previous discussions of this question but I must not have found the one I can understand.

 

I need to process directories and filenames created by people lucky enough not to realize how much pain apostrophe's in file names can cause. These (the apostrophes, not the people) can be escaped, like other special characters, in more than one way. I am looking for the way that lets me execute one Unix shell command at a time from Filemaker using the script step Perform AppleScript and, within that, the Applescript step:

 

do shell script"..."

 

For example, I want to list the contents of the folder:

/Volumes/Magirus/Jane's Patients

(note one single quote and one space)

 

The following works in Mac OS X Terminal (I think it's a bash shell by default):

ls /Volumes/Magirus/Jane\'s\ Patients

 

The following works in Filemaker's Perform Applescript step:

do shell script "ls /Volumes/Magirus/" (entered by hand)

 

To use a calculated field (e.g. myAppleScriptStep) this works:

myAppleScriptStep = "do shell script \"ls /Volumes/Magirus/\""

Perform Applescript <choose "Use Calculated Field" and select field myAppleScriptStep>

The backslashes here escape the double quotes required for: do shell script "...Unix command..."

 

However, the following does NOT work:

myAppleScriptStep = "do shell script \"ls /Volumes/Magirus/Jane\'s\ Patients/\""

Perform Applescript <choose "Use Calculated Field" and select field myAppleScriptStep>

The backslashes here escape the double quotes required for: do shell script "...Unix command..."

 

I have read about 3 possible solutions but cannot get them to work:

 

1. Use the Applescript function "quoted form of"

2. Convert the single quotes into something unintuitive like: ' becomes ''\' or something similar

3. Change the Unix shell from the one used by Applescript (tch?) to bash, and then execute the same command that works in Terminal

 

There is a 4th way, which works and I'll use if I have to, but seems cumbersome for a single command:

- Create a text file, commandsMac.txt, with the Unix commands that works in Terminal

- Execute, from Filemaker, a Unix "source" command o execute a file with a command to change line endings from Mac to Unix-compatible format (cat commandsMac.txt | tr "\r" "\n" > commandsUnix.txt)

- Execute the Unix command: source commandsUnix.txt

 

I would really like to get this to work more directly, using something like "quoted form of", or some Filemaker function to calculate a version of the Unix command that can be executed from within Filemaker.

 

I am open to any suggestions. If you can include a specific example of where to place backslashes that would be really helpful. Google has helped a lot, but I think the details are stumping me.

 

Pietro

Outcomes