我有以下命令行在终端
中运行良好重命名的/ \ d + / sprintf(“%04d”,$&)/ e'〜/ Downloads / test / * .pdf
但是我无法在applescript中转义引号(在脚本中有单引号和反斜杠),这是我试过的,applescript没有给我错误,但我没有重命名我的文件。
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获得的输出
tell current application
do shell script "/opt/local/bin/rename ''\\''s/\\d+/sprintf(\"%04d\",$&)/e'\\''' ~/Downloads/test/*.pdf"
--> ""
end tell
Result:
""
这正是我想要的,如输出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中查看结果,那么我会在结果中得到反斜杠
set inString to "'s/\\d+/sprintf(\"%04d\",$&)/e'"
do shell script "echo " & quoted form of inString
结果
"'s/\\d+/sprintf(\"%04d\",$&)/e'"
我经常工作但我无法获得工作脚本,请建议我一个解决方案,谢谢
答案 0 :(得分:1)
你的报价太多了。试试这个:
set inString to "s/\\d+/sprintf(\"%04d\",$&)/e"
do shell script "/opt/local/bin/rename " & quoted form of inString & " ~/Downloads/test/*.pdf"