0

If this code is called with CLP'S that have no spaces in them (such as "~ testing" or "/Volumes/BOOTCAMP testing") it runs fine. However, if the CLP's contain spaces (such as "/Volumes/Shared External testing", "~ test results" or "/Volumes/Shared External test results" then it either malfunctions or aborts with an error message.

The following code snippet is the minimum to demonstrate the problem:

on run (clp)
    if clp's length is not 2 then error "Incorrect Parameters"
end run

The actual app's relevant code is:

on run (clp)
    if clp's length is not 2 then error "Incorrect Parameters"
    local destination, libraryName
    set destination to clp's item 1
    set libraryName to clp's item 2

This app excepts a directory to save its data to as the first parameter and the filename to save it under as the second parameter. The first broken example would cause destination to be set to "/volumes/Shared" and libraryName to "External" and the rest ignored. Second broken example would cause destination to be set to "~" and libraryName to "test" and the rest ignored. The last broken example would cause the same results as the first example.

I have googled extensively and already tried enclosing the space containing parameter(s) in each of the following with no success: double quotes, single quotes, and {}. I also tried separating the enclosed parameters with commas rather than spaces and enclosing all the parameters in {}. Again, none of these met with success. I also consulted "info osascript" to no avail.

Does anyone have a solution, or even more ideas to try?

Bryan Dunphy
  • 799
  • 1
  • 10
  • 22
  • The error is going to be in how you're assigning clp. Show that code. Also, you can log clp as the first line to see what's up. – jweaks Feb 08 '17 at 06:01

1 Answers1

0

The script for test:

on run (clp)
    if clp's length is not 2 then error "Incorrect Parameters"
    local destination, libraryName
    set destination to clp's item 1
    set libraryName to clp's item 2
    display dialog libraryName -- libraryName contains "test 123"
    display dialog destination -- destination contains "/Volumes/Shared External"
end run

When I execute this command in the bash shell

osascript '/the full path/of the/testingScript.scpt' '/Volumes/Shared External' 'test 123'

The dialogs display both parameters correctly.

jackjr300
  • 7,111
  • 2
  • 15
  • 25
  • I just manually tested your command line/test script with every shell in "/etc/shells" and it worked with **all of them**! – Bryan Dunphy Feb 10 '17 at 01:53