1

Automator に Applescript コードを使用してファイルの拡張子を取得する方法があり、それが特定の拡張子 (.pdfまたは など.rtf) に等しい場合、その拡張子の特定のフォルダーに移動する方法があるかどうか疑問に思っていました (例if (extension == pdf) { move to folder "~/PDF Files" } else if (extension == rtf) { move to folder "~/Rich Text Files" })

4

2 に答える 2

3

これがアップルスクリプトです。あなたの要求は簡単だったので、私はあなたのためにそれを書きました。サブルーチン「getNameAndExtension(F)」でファイル拡張子を取得する方法に注意してください。通常、Finder からファイル拡張子 (名前拡張子と呼ばれます) を取得できますが、Finder は常に信頼できるとは限らないことがわかったので、常にそのサブルーチンを使用しています。そのサブルーチンは常に信頼できます。

set homeFolder to path to home folder as text
set rtfFolderName to "Rich Text Files"
set pdfFolderName to "PDF Files"

-- choose the files
set theFiles to choose file with prompt "Choose RTF or PDF files to move into your home folder" with multiple selections allowed

-- make sure the folders exist
tell application "Finder"
    if not (exists folder (homeFolder & rtfFolderName)) then
        make new folder at folder homeFolder with properties {name:rtfFolderName}
    end if
    if not (exists folder (homeFolder & pdfFolderName)) then
        make new folder at folder homeFolder with properties {name:pdfFolderName}
    end if
end tell

-- move the files
repeat with aFile in theFiles
    set fileExtension to item 2 of getNameAndExtension(aFile)
    if fileExtension is "rtf" then
        tell application "Finder"
            move aFile to folder (homeFolder & rtfFolderName)
        end tell
    else if fileExtension is "pdf" then
        tell application "Finder"
            move aFile to folder (homeFolder & pdfFolderName)
        end tell
    end if
end repeat



(*=============== SUBROUTINES ===============*)
on getNameAndExtension(F)
    set F to F as Unicode text
    set {name:Nm, name extension:Ex} to info for file F without size
    if Ex is missing value then set Ex to ""
    if Ex is not "" then
        set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
    end if
    return {Nm, Ex}
end getNameAndExtension
于 2010-07-29T12:30:41.290 に答える
0

私は今Appleにいないので、Automatorをいじってそれを理解することはできません。ただし、ファインダーをリストビューに切り替えてこれを行うことができる場合は、タイプで並べ替えてから、同じタイプのファイルのブロックを選択して、適切なフォルダーにドラッグします。

于 2010-07-28T18:16:58.663 に答える