2013-10-13 140 views
1

我想將「Booklet xxx.pdf kopie.pdf」的醜陋文件名(作爲我的不良編程的副產品)更改爲「xxx.pdf」。的Automator它更改爲>「xxx.pdf」(在文件名前面的很煩人的空間...刪除部分文件名

這是我能想出...

tell application "Finder" 
    set allFiles to selection 
    search of (name of every item of allFiles) for "Booklet " 
try 
    if file exists then delete "Booklet " of name 
end try 
    search of (name of every item of allFiles) for ".pdf kopie" 
try 
    if file exists then delete ".pdf kopie" of name 
end try 
    end tell 

非常感謝!

回答

2

您可以通過設置name屬性重命名文件:

activate application "SystemUIServer" -- http://www.openradar.me/9406282 
tell application "Finder" 
    activate 
    repeat with f in (get selection) 
     if name of f ends with "kopie.pdf" then 
      set name of f to text 9 thru -11 of (get name of f) 
     end if 
    end repeat 
end tell 

或者在shell中運行是這樣的:

cd directory; for f in *kopie.pdf; do f2=${f% *}; mv "$f" "${f2##* }"; done 

${f% *}f末端去除最短​ *圖案和${f2##* }去除的f2開始時的最長* ​圖案。

+0

感謝您幫助這個菜鳥!它的工作原理:-)計算出9到11的意思,但現在我明白(字符)... – Mauritz