次から始めて、あなたのニーズを満たすためにそれを変更することができます。テストされていませんが、コンパイルされます。
set p to POSIX file "/Users/kaass/Desktop/test/"
tell application "Finder" to set filelist to name of every file of folder p
repeat with filename in filelist
set text item delimiters to ""
if text -5 thru -1 of filename is equal to ".epub" then
set temp to items 1 thru -6 of filename as text
set text item delimiters to " - "
set myWord to text items 1 thru -1 of temp
set title to myWord's last item as text
if myWord's length is equal to 3 then set series to myWord's second item as text
set myWord to item 1 of myWord as text
if myWord contains "," then
set text item delimiters to ", "
else
set text item delimiters to " "
end if
set author to (text item 2 of myWord) & space & (text item 1 of myWord)
set path_and_filename to POSIX path of file p & filename
do shell script "echo Processing file " & quoted form of path_and_filename & ": " & author & " +++ " & title
do shell script "/Applications/calibre.app/Contents/MacOS/ebook-meta " & quoted form of path_and_filename & " -a " & quoted form of author & " -t " & quoted form of title
end if
end repeat
変更が必要な場合は、ただコメントしてください。
ありがとう、これは素晴らしいです。これを実行するには、いくつかの変更が必要でした。まず、ifのif -5〜th -1が ".epub" then "と等しい場合、最初の区切り文字を保存して復元する必要がありました。 ifの最後)、それ以外の場合は、リストの最初の項目(「oldDelimitersをテキスト項目区切り文字に設定」および「テキスト項目区切り文字をoldDelimitersに設定」)にのみ機能します。最後に、別の質問があります。「ナショナルジオグラフィック」のような名前がある場合は、どのように「姓、名字」をフェールセーフにすることができますか? –
あなたの入力に基づいてコードを更新しました。 –
ebook-metaの呼び出し以外は魅力的です。エンコード/エスケープには問題があるようです。私はいくつかのGoogleの調査を行い、引用されたフォームを追加し、 "do shell script"という行を変更するとecho /Applications/calibre.app/Contents/MacOS/ebook-meta \ ""&filename& "\" -a \ """""""""の形式を引用& "\" ""出力を得ます "/Applications/calibre.app/Contents/MacOS/ebook-meta" Adler-オルセン、Jussi - CarlMørck1 - Erbarmen.mobi '-a' Jussi Adler-Olsen '-t' CarlMørck1 - Erbarmen '"これをコマンドラインに貼り付けると正しく実行されます。スクリプトによって実行される直接エコーと、「そのようなファイルまたはディレクトリ:U」なし –