on run {input} set theItems to input tell application "Finder" if number of items of (theItems as list) < 2 then return else doAS(theItems) of me end if end tell end run on doAS(theItems) set theYear to (year of (current date)) as string set theMonth to ((month of (current date)) as number) as string if (number of characters of theMonth) = 1 then set theMonth to ("0" & theMonth) set theDay to (day of (current date)) as string if (number of characters of theDay) = 1 then set theDay to ("0" & theDay) set theHour to (hours of (current date)) as string if (number of characters of theHour) = 1 then set theHour to ("0" & theHour) set theMinutes to (minutes of (current date)) as string if (number of characters of theMinutes) = 1 then set theMinutes to ("0" & theMinutes) set theSeconds to (seconds of (current date)) as string if (number of characters of theSeconds) = 1 then set theSeconds to ("0" & theSeconds) set theText to "新規フォルダ-" & (theYear & theMonth & theDay & theHour & theMinutes & theSeconds) tell application "Finder" set theContainer to (container of (item 1 of theItems)) as alias set theFolder to (make new folder at theContainer) move theItems to theFolder set movedItems to result namingFolder(movedItems, theText, theFolder, theContainer) of me end tell end doAS on namingFolder(movedItems, theText, theFolder, theContainer) tell application "Finder" display dialog "新しいフォルダの名前: " & return & "" default answer theText buttons {"キャンセル", "内包する項目名", "OK"} default button 3 set theResult to result if button returned of theResult is "OK" then set folderName to (text returned of theResult) if folderName is "" then set folderName to theText if folderName starts with "." then display dialog ""."で始まる名前は使えません。" namingFolder(movedItems, theText, theFolder, theContainer) of me else if folderName contains ":" then display dialog "":"が含まれる名前は使えません。" namingFolder(movedItems, theText, theFolder, theContainer) of me else set existsFolder to (exists of (folder folderName of theContainer)) if existsFolder is true then set n to 1 repeat until existsFolder is false set newFolderName to (folderName & " " & n) set n to (n + 1) set existsFolder to (exists of (folder newFolderName of theContainer)) end repeat set name of theFolder to newFolderName else set name of theFolder to folderName end if end if else if button returned of theResult is "内包する項目名" then editText(movedItems, theText, theFolder, theContainer) of me end if end tell end namingFolder on editText(movedItems, theText, theFolder, theContainer) tell application "Finder" set tmp to AppleScript's text item delimiters set AppleScript's text item delimiters to "." try set itemNameList to {} repeat with i from 1 to (number of items of movedItems) set tmpName to "" as Unicode text --ここの as Unicode text が重要。 set itemName to (name of item i of movedItems) if (number of every text item of itemName) > 1 then set textList to (text items 1 thru -2 of (every text item of itemName)) repeat with j from 1 to (number of items of textList) set tmpName to tmpName & (item j of textList) if j is not (number of items of textList) then set tmpName to tmpName & "." end repeat else set tmpName to itemName end if set itemNameList to (itemNameList & tmpName) end repeat set AppleScript's text item delimiters to tmp on error set AppleScript's text item delimiters to tmp end try choose from list itemNameList default items (item 1 of itemNameList) if result is not false then set theText to (item 1 of result) namingFolder(movedItems, theText, theFolder, theContainer) of me end if end tell end editText