Automator (move finder items)

I have a service that moves finder items to a particular folder. Since I started using this I noticed I occasionally will need to move an item with the same name into this folder. Is there a way I can get the service to move the second item with the same name, but instead of overwriting the first item, have it add a -1 or something? If I open something like a zip file multiple times in finder, it creates the second one with a 1 after the name. That's exactly what I need. Any way to do that with a service like this?

Macbook Pro, Mac OS X (10.6.1)

Posted on Dec 31, 2009 10:57 AM

Reply
19 replies

Jan 2, 2010 8:17 PM in response to V.K.

Ahhh, I see. I used the second example here, and it worked fine. However, this operation is a move, not a copy paste, right? I noticed that might be the case when the file remained on the desktop after running the script. Could that be because the target folder is in a different volume of my HD? It worked fine when I made a move item with automator, and I didn't have to do anything to delete the original.

Message was edited by: sterlingfive

Jan 2, 2010 8:59 PM in response to V.K.

No problem, I'll investigate it. It does work fine to every folder I've tested with that is within the same volume on my HD. It's only when it's going to a different partition that it doesn't work. Anyway, I don't have hundreds of these to do at a time, so I can quickly move them to trash after the service works, at least until I can figure out what's going on. I'll mozy on over to an applescript forum and do a little poking around about it!

thanks again, you were a huge help!
sterling

Mar 8, 2010 9:17 AM in response to V.K.

I have been discussing this script on another board and finally got exactly what I need. I went a slightly different direction and used an applescript application instead of an automator application. The script does the entire process including the naming of the item and the move. Then, instead of making a service, I used butler to create a keyboard shortcut to the application. Now, I just need to select the files in finder, and hit my keyboard shortcut to process the files. !Voila! Exactly what I needed!

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

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator (move finder items)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.