Automator (move finder items)
Macbook Pro, Mac OS X (10.6.1)
Macbook Pro, Mac OS X (10.6.1)
property destinationFolder : choose folder with prompt "Choose the
destination folder" -- or insert the path here
on open objectsToMove
tell application "Finder" to set myContainer to (container of (item 1
of objectsToMove)) as alias
renameAndMoveFiles(objectsToMove, myContainer)
end open
on run
tell application "Finder" to set objectsToMove to selection
if objectsToMove is {} then display dialog "No items selected in the
Finder" buttons "Quit" default button 1 cancel button 1
tell application "Finder" to set myContainer to (container of (item 1
of objectsToMove)) as alias
renameAndMoveFiles(objectsToMove, myContainer)
end run
-- the handler to rename and move files
on renameAndMoveFiles(theObjects, theFolder)
repeat with anItem in theObjects
set anItem to anItem as alias
tell application "Finder"
set creationDate to (creation date of anItem)
set myDays to my twoCharacterDate(creationDate, "day")
set myMonth to my twoCharacterDate(creationDate, "month")
set newNameString to (myMonth & "-" & myDays & "-" & (year of
creationDate) & " USPSLabel.pdf") as string
set name of anItem to newNameString
set anItem to (item newNameString of theFolder) as alias
if exists item newNameString of destinationFolder then
set extLength to (count characters of (name extension of (info for
anItem)))
set nameWithoutExt to (characters 1 thru -(extLength + 2) of (name
of (info for anItem))) as string
set i to 1
set nameToCheck to (nameWithoutExt & "-" & my twoDigitsInteger(i)
& "." & (name extension of (info for anItem))) as string
repeat
if not (exists (item nameToCheck of destinationFolder)) then
exit repeat
else
set i to i + 1
set nameToCheck to (nameWithoutExt & "-" & my
twoDigitsInteger(i) & "." & (name extension of (info for anItem))) as
string
end if
end repeat
set newName to (nameWithoutExt & "-" & my twoDigitsInteger(i) &
"." & name extension of (info for anItem)) as string
set name of anItem to newName
set anItem to (item newName of theFolder) as alias
end if
set itemToDelete to name of anItem
move anItem to destinationFolder
if (exists item itemToDelete of alias (theFolder as string)) then
delete (item itemToDelete of theFolder)
end tell
end repeat
end renameAndMoveFiles
on twoCharacterDate(aDate, aType)
set myScript to ("get (" & aType & " of (date ("" & (aDate as
string) & ""))) as integer") as string
set myResult to (run script myScript)
if (count every character of (myResult as string)) is 1 then set
myResult to (0 & myResult) as string
return myResult
end twoCharacterDate
on twoDigitsInteger(anInt)
set anInt to anInt as string
if (count every character of anInt) is 1 then set anInt to (0 &
anInt) as string
return anInt
end twoDigitsInteger
Automator (move finder items)