I've built an Automator application that takes a file and (after an admin password is entered) changes the ownership and moves it to another user's folder. I'm using the command:
mv -i source target
to move the file. The -i option will prompt before overwriting an existing file with the same name. But this prompt is only on the command line. If there is a duplicate file name, my Automator application acts as if it worked but nothing really happens.
My question:
How do I detect the -i prompt in the shell script and display it as a dialog in the Finder? Here's the complete "Run Shell Script" action:## get password then chown file
echo $1 | sudo -Sk chown aklap "$2";
## password, then move file
echo $1 | sudo -Sk mv -i "$2" /destination;
x=`echo $2 | awk -F/ '{print $NF}'`; ## get file name (awk to remove remove path)
osascript <<EOD
tell app "System Events" to display dialog "The file: \"$x\" has been moved to /destination"
EOD