applescriptを実行するとcurlコマンドが失敗するのに、ターミナルで直接実行すると正常に機能するのはなぜですか?

Aug 19 2020

組み込みのWebインターフェイスを使用して、インストールされているプロジェクターを制御するためのAppleScriptを作成しようとしています。適切なURLにpingを実行し、コマンドラインから必要に応じてプロジェクターを制御できるcurlコマンドがあります。これをアップルスクリプトに組み込むと(ショーコントロールソフトウェアで必要)、

私のapplescriptは現在次のようになっています:

set theUrl to "http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on"
set theUsername to "dispadmin" -- set this to the username for the projector
set thePassword to "password" --set this to the password for the projector

set myFile to (POSIX path of (path to temporary items)) & "curl_downloaded_file.xml"

set curlScript to "/usr/bin/curl --connect-timeout 1 --anyauth --user" & " " & theUsername & ":" & thePassword & " -L " & theUrl & " -o " & myFile

display dialog "my variable: " & curlScript

do shell script curlScript

このdisplay dialog行は、curlコマンドがどのように表示されるかを示すためのデバッグ用です。これを実行すると、次のようになります。

/usr/bin/curl --connect-timeout 1 --anyauth --user dispadmin:password -L http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on -o /private/var/folders/zs/f1hpkd2x281fvzyh4zd5dpcw0000gn/T/TemporaryItems/curl_downloaded_file.xml

どちらが正しいようです。URLの前後に引用符を追加すると、ターミナルでこのコマンドを問題なく実行して目的の効果を得ることができますが、Applescriptは引き続き次のエラーを吐き出します。

error "sh: -o: command not found
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   350  100   350    0     0  38888      0 --:--:-- --:--:-- --:--:-- 38888

100   267    0   267    0     0   5235      0 --:--:-- --:--:-- --:--:--  5235" number 127

これはcurlが実行されているように見えますが、プロジェクターのWebサーバーにヒットしてcontrollをトリガーしerror "sh: -o: command not foundません。また、コマンドが正しく解析/渡されていないと思われます。

私はここで何が間違っているのですか?

回答

2 user3439894 Aug 19 2020 at 22:00

一方

http://192.168.0.103/cgi-bin/proj_ctl.cgi?key=shutter_on&lang=e&osd=on

ブラウザでは正常に動作しますが、シェルでは動作しません。

この問題を解決するには、URLを引用する必要があります

set curlScript to ...変化theUrlのいずれかにtheUrl's quoted formか:quoted form of theUrl