Curl 在“中嵌套引号”;do shell脚本“-命令原因错误

Curl 在“中嵌套引号”;do shell脚本“-命令原因错误,curl,applescript,adobe-indesign,extendscript,Curl,Applescript,Adobe Indesign,Extendscript,我正在从(indesign)extendscript jsx文件运行一个cURL shell脚本 这对于简单的查询很有效,但是在下面的命令中,您可以看到我有相当多的引号嵌套,这似乎使命令失败!它没有抛出任何错误,但是Wordpress帖子没有被更改 var command = 'do shell script "curl -X PUT -H \'Content-Type: application/json\' -d \' { \'title\': \'Blub\', \'content_raw\

我正在从(indesign)extendscript jsx文件运行一个cURL shell脚本

这对于简单的查询很有效,但是在下面的命令中,您可以看到我有相当多的引号嵌套,这似乎使命令失败!它没有抛出任何错误,但是Wordpress帖子没有被更改

var command = 'do shell script "curl -X PUT -H \'Content-Type: application/json\' -d \' { \'title\': \'Blub\', \'content_raw\': \'Updated post content\' } \' -u username:password http://website.com/wp-json/wp/v2/cpt/12/"';
var response = app.doScript(command, ScriptLanguage.APPLESCRIPT_LANGUAGE);
当我这样写的时候,它抛出了一个错误,因为引用错误:

var command = 'do shell script "curl -X PUT -H \"Content-Type: application/json\" -d \" { \"title\": \"Blub\", \"content_raw\": \"Updated post content\" } \" -u admin:password http://seebook.dev/wp-json/wp/v2/calendar/12/"';
当我直接在终端中运行命令时,它会工作

curl -X PUT -H "Content-Type: application/json" -d " { \"title\": \"Updates Title\", \"content_raw\": \"Updated post content\" } " -u username:password http://website.com/wp-json/wp/v2/cpt/12/
这个版本也是如此:

var command = 'do shell script "curl -X PUT -H \"Content-Type: application/json\" -d \" { \'title\': \'Blub\', \'content_raw\': \'Updated post content\' } \" -u username:password http://website.com/wp-json/wp/v2/cpt/12/"';
如何编写查询以使其工作

我想这是个很难回答的问题,但我以前从未遇到过这样的情况

祝你一切顺利,
Lukas

试试这个,外部引号必须是双引号,
内容类型
部分用单引号括起来,查询是用表达式的
引号形式创建的

set query to "{ \"title\": \"Updates Title\", \"content_raw\": \"Updated post content\" }"
do shell script "curl -X PUT -H 'Content-Type: application/json' -d " & quoted form of query & " -u username:password http://website.com/wp-json/wp/v2/cpt/12/"

只是一个想法。。。你为什么要用Applescript呢?您当然不需要启动Applescript来启动shell命令—您不能直接启动
curl
?或者直接启动
bash
,而不使用额外的Applescript层?