Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iBug2

macrumors 601
Original poster
Jun 12, 2005
4,533
857
I'm trying to create an automator shell script to cut/paste. It'll function exactly like copy/paste. i.e. I'll just copy file/files with command+c like always, but then I'll create an automator which uses the "mv" terminal app to move the files which works exactly like cut paste.

I need some help since I don't know the syntax for creating shell scripts.

What I did so far is to do it in automator with Apple Script which goes like the following:

on run {input, parameters}
tell application "Finder"
set theWindow to window 1
set thePath to quoted form of (POSIX path of (target of theWindow as string))
end tell

tell application "Terminal"

do script with command "mv \"" & input & "\"" & thePath in window 1
end tell
return input
end run

This gets the copied file path from clipboard before, as input, and then recognizes the active finder window as thePath so then executes the mv command for the input file to the thePath window.

It doesn't work as expected since it connects both file/window paths into a single path instead of leaving a space between them so the mv command can't recognize two separate paths.

What's the correct syntax for that line

do script with command "mv \"" & input & "\"" & thePath in window 1

to leave a space between input and thePath under the mv command?

Also this requires the terminal app to be open in the background.

After I get this to work I want to do the exact same thing using shell script within automator, so I won't need Terminal to be open all the time.

And the next step will be to cut/paste multiple files/folders but that should be easy to do once I get the hang of it.


P.S. I know there are 3rd party utilities and other ways to do this with automator, but I want to do it by "mv". It seems like the most elegant solution since mv is the simplest move command one can get.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.