2つのフォルダがあります
最初のフォルダーには、2 番目のフォルダーのサブフォルダーに移動したいすべてのファイルが含まれています。ファイル名とフォルダ名の両方の最初の 7 文字に基づいてこれを行いたいと思います。
したがって、FOLDER 2 のサブフォルダーの最初の 7 文字が FOLDER 1 のファイルの最初の 7 文字と一致する場合、ファイルは FOLDER 2 のサブフォルダーに移動されます。
現在、動作する Applescript がありますが、非常に遅いです。
これまでのスクリプトは次のとおりです。
set mgFileList to ""
set mgDestFolder to ""
set mgFilesFolder to (choose folder with prompt "Where are the files stored which you would like to move to the destination?")
set mgDestFolder to (choose folder with prompt "Where is the destination folder?")
set folderList to contents of mgDestFolder
tell application "Finder" to set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to getPrefix(name of aFile)
tell application "Finder"
try
set destinationFolder to (1st folder of mgDestFolder whose name begins with prefix)
move aFile to destinationFolder
end try
end tell
end repeat
on getPrefix(aName)
set prefix to text 1 thru 7 of aName
return prefix
end getPrefix
私が Applescripting を始めたのはつい最近のことです。Applescript 内でこれをより効率的に行うことはできますか? シェルスクリプトで動作するソリューションを探しましたが(おそらくはるかに高速になると思います)、それらを機能させることができませんでした。
私はOSX Mountain Lion 10.8.4に取り組んでいます
- 編集
これまでに作成したスクリプトの間違ったバージョンをアップロードしたことがわかりました。上記は動作しているスクリプトですが、非常に遅いです。おそらく、シェルスクリプトを使用していないためです。
- - - - - - - -アップデート - - - - - - - - - -
以下は、現在非常に高速に動作している最終的なスクリプトです。
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
set mgDestFolder to choose folder with prompt "Where is the destination folder?"
tell application "System Events"
set fileList to files of mgFilesFolder whose name does not start with "."
repeat with aFile in fileList
set prefix to my getPrefix(name of aFile)
try
set destinationFolder to (1st folder of mgDestFolder whose name begins with prefix)
move aFile to POSIX path of destinationFolder
end try
end repeat
end tell
on getPrefix(aName)
try
set prefix to text 1 thru 7 of aName
return prefix
on error
return aName
end try
end getPrefix