Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am trying to find a way to automatically (without user intervention) move a file from A to B, replacing B if it exists, ideally by putting the existing copy of B into the appropriate Trash folder.

This will be done in a shell script. Eventually A and B will beed to be $VARIABLES like this:

/usr/bin/osascript <<EOT
tell application "Finder"
    move POSIX file "$SOURCE" to POSIX file “$DEST" with replacing
end tell
EOT

but I can’t even get this to work without variables, such as this:

/usr/bin/osascript <<EOT
tell application "Finder"
    move POSIX file "/Users/luomat/Desktop/1.txt" to POSIX file "/Users/luomat/Desktop/2.txt" with replacing
end tell
EOT

I took that syntax pretty much directly from Stackoverflow 14058061 but I get this result:

24:132: execution error: Finder got an error: AppleEvent handler failed. (-10000)

I also came across a MacTech article which suggested using replacing true so I tried:

/usr/bin/osascript <<EOT
tell application "Finder"
    move POSIX file "/Users/luomat/Desktop/1.txt" to POSIX file "/Users/luomat/Desktop/2.txt" replacing true
end tell
EOT

but it still says:

24:132: execution error: Finder got an error: AppleEvent handler failed. (-10000)

Please note that stackoverflow #12708195 I am not trying to prompt the user to do this, but ideally would like it to happen ‘automagically’ as the kids say.

So… what am I doing wrong and/or missing? Trying to Google for information on error code (-10000) pretty much tells me that it means “AppleScript failed” which isn’t all that helpful.

share|improve this question
    
Technically it's more like an AppleScript, and it's not the easiest thing to do when combining it sometimes; Any reason you're not doing it entirely as a shell script? –  l'L'l Jan 22 at 21:58
    
It's going to be part of a much larger shell script, this is only a small piece of it. –  TJ Luoma Jan 23 at 6:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.