2017-02-08 5 views
0

"〜testing"や "/ Volumes/BOOTCAMP testing"のような、スペースを含まないCLPでこのコードを呼び出すと、正常に動作します。ただし、CLPに "/ Volumes/Shared External testing"、 "〜test results"、 "/ Volumes/Shared External test results"などのスペースが含まれている場合は、エラーメッセージを表示して誤動作または異常終了します。osascript/ApplescriptにSPACESを含むコマンドラインパラメータを受け取るにはどうすればよいですか?

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

実際のアプリの関連コードは次のとおりです:

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 

このアプリは、最初のパラメータおよびファイル名へとそのデータを保存するディレクトリをexceptsでコードスニペットを、次のことは、問題を実証するための最小値でありますそれを第2のパラメータとして保存します。壊れた例では、宛先は "/ volumes/Shared"に設定され、libraryNameは "External"に設定され、残りは無視されます。 2番目の壊れた例は、宛先を "〜"に設定し、libraryNameを "テスト"に設定し、残りは無視します。最後の壊れた例は、最初の例と同じ結果を引き起こします。

私は広く探ってきて、次のそれぞれにパラメータを含むスペースを二重引用符、一重引用符、および{}で囲んでみました。また、囲まれたパラメータをスペースではなくカンマで区切り、すべてのパラメータを{}で囲んでみました。再び、これらのどれもが成功を収めました。私はまた、 "info osascript"と相談して無駄にしました。

誰にでも解決策がありますか、それ以上のアイデアはありますか?

+0

エラーは、clpをどのように割り当てるかで決まります。そのコードを表示します。また、clpを最初の行として記録して、何が起きているのかを確認することもできます。 – jweaks

答えて

0

テスト用スクリプト:

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 

私はダイアログが正しく両方のパラメータを表示のbashシェル

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

を、このコマンドを実行します。

+0

完璧に動作します、ありがとうございます –

+0

"/ etc/shells"のすべてのシェルでコマンドライン/テストスクリプトを手動でテストしましたが、**すべて**で動作しました**! –

関連する問題