2013-09-16 68 views
0

我有以下命令行工作良好終端在AppleScript中轉義shell參數?

重命名的/ \ d +/sprintf的( 「%04D」,$ &)/ E'〜/下載/測試/ *。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' 

再次如果我放棄outpu噸我的劇本,只是看結果AppleScript的話,我的結果讓反斜槓

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

結果

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

我工作圍繞了很多,但我沒能工作的腳本,請建議我的解決方案,謝謝

回答

1

你有太多的報價。試試這個:

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