次のコマンドラインがターミナルでうまく機能します
's/\d+/sprintf("%04d",$&)/e' の名前を変更 ~/Downloads/test/*.pdf
しかし、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'"
私は多くのことを回避しましたが、動作するスクリプトを取得できませんでした。解決策を提案してください、ありがとう