Lil Script Help in Moving a File?

Hey,

I just need to move a file, with a changed name, from one folder to another.
Been experimenting with various versions of this with no luck.

set newPath to ((path to downloads folder as text) & “192.168.1.36:29:fs_” & (value of variable “iPhoneMovieNumber”) & “.mov”)
set targetPath to “Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes:A New iPhone Movie.mov”

tell application “Finder”
move newPath to targetPath
end tell

Any help greatly appreciated!

Thanks,

Carl

I’m on way to little sleep so I won’t attempt to solve this. But this script works for moving stuff. Maybe it will be useful:

tell application "Finder"
	set theObject to somePath
	move theObject to someFOLDER(!)
end tell

I think you might be confusing moving something to a folder and changing it’s name.

Hi,

the Finder cannot move and rename a file at the same time.
Either first move it then rename it


set newPath to ((path to downloads folder as text) & "192.168.1.36:29:fs_" & iPhoneMovieNumber & ".mov")
set targetPath to "Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes:"

tell application "Finder"
	set movedFile to move file newPath to folder targetPath
	set name of movedFile to "A New iPhone Movie.mov"
end tell

or use the shell.

You should always add object specifiers (like file or folder) to Finder file actions. The raw string path is not sufficient

Thanks. Nuts, still can’t get it to work.
Maybe the catch is the insertion of the variable name into the path?
I’m executing this from within my home automation app Indigo.

Tried variations of this:

set newPath to ((path to downloads folder as text) & “192.168.1.36:29:fs_” & (value of variable “iPhoneMovieNumber”) & “.mov”)
set targetPath to “Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes”

tell application “Finder”
set movedFile to move file newPath to folder targetPath
set name of movedFile to “A New iPhone Movie.mov”
end tell

Edit: Ta Dah…got it too work, except it needs to write over the “A New iPhone Movie.mov” if it exists.

Any ideas?

Thanks,

Carl

value of variable “iPhoneMovieNumber” is no valid AppleScript syntax unlike it’s part of a scripting addition or part of an application"s terminology. In the latter case it must be with an application tell block

Is there something to add to the script that will force it to write over the “A New iPhone Movie.mov” file
if it exists?

Thanks,

Carl

use the shell


set newPath to POSIX path of (path to downloads folder) & "192.168.1.36:29:fs_" & iPhoneMovieNumber & ".mov"
set targetPath to POSIX path of ("Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes:A New iPhone Movie.mov")
do shell script "/bin/mv -f " & quoted form of newPath & space & quoted form of targetPath

Can’t get that one to compile, Is it possible to do with an AS?

Carl

The snippet must compile. What error message do you get

Trying this:

set newPath to POSIX path of (path to downloads folder) & “192.168.1.36:29:fs_” & (value of variable “iPhoneMovieNumber”) & “.mov”
set targetPath to POSIX path of (“Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes:A New iPhone Movie.mov”)
¨do shell script "/bin/mv -f " & quoted form of newPath & space & quoted form of targetPath

but get "Expected end of line but found unknown token.

Thanks for all your help.

Carl

This compiles but doesn’t move the file.

set newPath to ((path to downloads folder as text) & “192.168.1.36:29:fs_” & (value of variable “iPhoneMovieNumber”) & “.mov”)
set targetPath to “Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes”

do shell script "/bin/mv -f " & quoted form of newPath & space & quoted form of targetPath

Carl

I’m confused where this value of variable “iPhoneMovieNumber” comes from.
You need POSIX paths (slash separated) for the shell

It’s a number stored in a variable in my automation app Indigo that determines the file number
to be moved. If the script is executed outside of Indigo that part won’t work.

Isn’t there something like “using replace” that could be added, or maybe delete the file before runnng
the move?

Carl

Got the delete before moving to work. Thanks a bunch for all your help!!

Carl

sigh, it’s hard to help just with a chunk of code.
You should move the shell part out of the Indigo tell block


tell application "Indigo"
	--.
	set iPhoneMovieNumber to value of variable "iPhoneMovieNumber"
end tell

set newPath to POSIX path of (path to downloads folder) & "192.168.1.36:29:fs_" & iPhoneMovieNumber & ".mov"
set targetPath to POSIX path of ("Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes:A New iPhone Movie.mov")
do shell script "/bin/mv -f " & quoted form of newPath & space & quoted form of targetPath


The above script compiles but doesn’t execute.

This one works, but leaves the original intact, it just copies it to the new location.

set newPath to ((path to downloads folder as text) & “192.168.1.36:29:fs_” & (value of variable “iPhoneMovieNumber”) & “.mov”)
set targetPath to “Indigo Backup:Users:TV:Music:iTunes:Automatically Add to iTunes”
tell application “Finder”
–delete file “Indigo Backup:Users:TV:Music:iTunes:Automatically Add to --iTunes:A New iPhone Movie.mov”
set movedFile to move file newPath to folder targetPath
set name of movedFile to “AA New iPhone Movie.mov”
end tell

I thought the move command would do just that, take the original and move it somewhere else.

Thanks,

Carl

That’s because you are moving a file to another disk. It has always worked like this (AFAICT).

Yet another Doh! moment.

Thanks,

Carl