逃避AppleScript的壳论点? [英] escape shell arguments in AppleScript?

查看:148
本文介绍了逃避AppleScript的壳论点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下命令行运行良好的终端

I have the following command line works well in terminal

重命名的/ \\ D + / sprintf的(%04D,$&安培;)/ E'〜/下载/测试/ * PDF

rename 's/\d+/sprintf("%04d",$&)/e' ~/Downloads/test/*.pdf

但我无法逃脱引号(在脚本中单引号和反斜杠)在AppleScript的,这就是我想,AppleScript的没有给我的错误,但我没有得到我的文件重命名。

but I couldn't escape quotes (have single quote and backslash in the script) in applescript, this is what I tried, applescript didn't give me error but I didn't get my files renamed.

 set renamer_command to "'s/\\d+/sprintf(\"%04d\",$&)/e'"
 do shell script "/opt/local/bin/rename " & quoted form of renamer_command & " ~/Downloads/test/*.pdf"

这是输出从我得到了Applescript

This is the output I get from Applescript

 tell current application
do shell script "/opt/local/bin/rename ''\\''s/\\d+/sprintf(\"%04d\",$&)/e'\\''' ~/Downloads/test/*.pdf"
    --> ""
 end tell
 Result:
""

这是给人正是我想要的在输出看到example.txt的

This is gives exactly what I want as seen in the output example.txt

 set inString to "'s/\\d+/sprintf(\"%04d\",$&)/e'"
 do shell script "echo " & quoted form of inString & " > ~/Desktop/example.txt"

结果

 's/\d+/sprintf("%04d",$&)/e'

同样地,如果我在脚本输出下降,只是看结果AppleScript的话,我的结果让反斜杠

Again if I drop the output in my script and just look at the result in applescript then I get backslash in the result

 set inString to "'s/\\d+/sprintf(\"%04d\",$&)/e'"
 do shell script "echo " & quoted form of inString

结果

 "'s/\\d+/sprintf(\"%04d\",$&)/e'"

我的工作开了不少,但我不能获得工作的脚本,请建议我一个解决方案,谢谢

I worked around a lot but I couldn't get working script, please suggest me a solution, thanks

推荐答案

您有太多的引号。试试这个:

You have too many quotes. Try this:

set inString to "s/\\d+/sprintf(\"%04d\",$&)/e"
do shell script "/opt/local/bin/rename " & quoted form of inString & " ~/Downloads/test/*.pdf"

这篇关于逃避AppleScript的壳论点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆