Me again
There is one last piece of my project I can not figure out. I drop a file onto a droplet and it duplicates the dropped file into a mounted network folder, but I can’t figure out how to rename that file after it is duplicated.
On open these
set source to (these as text)
set destination to "mounted network folder:documents"
tell application "finder"
duplicate file source to folder destination with replacing
set name of file destnation to "Newname.MOV"
end tell
end open
What I am trying to accomplish
1.) drop an .MOV file onto a droplet
2.) duplicate that droplet to a predesignated location on a mounted network share
3.) change the name of the duplicated file in its new location to fixed predetermined name “1.MOV”
Can you help I can not figure out how to do this. If I knew the file name of the dropped file in advance I could write this script but I won’t know the dropped file name in advance. I need to somehow get the file name of the dropped file then apend it to the path of the new duplicate location with a set name command.
Also this will be the only file in the folder, so a script to just rename all files in the folder would work too.
I found a solution to do this by renaming all files in the folder. This works for me because at the beginning of the script I clear that directory. Since this file is guaranteed to be the only file in the directory I can get away with a script that renames all files in the directory
set destination to "Mounted network drive:Documents"
tell application "Finder"
set file_list to every file in folder destination
repeat with myfile in file_list
set name of myfile to "NewName.MOV"
end repeat
end tell
However this is such a hacky method I would appreciate some help to target the single file for renaming. Where I am stumbling is I don;t know how to pull the dropped file name and then create a script syntax to change the file name in its new location after the duplicate.
Here’s how you can rename the copied file in the destination folder. We know the path of the copied file is the destination folder’s path plus the name of the original file. So now that you have the path you can rename it.
Note: in your code “these” is a list. A list can have one or more items, therefore to get the first file in that list (i.e. source) we get item 1 from the list.
on open these
set source to (item 1 of these) as text
set destination to "mounted network folder:documents"
tell application "Finder"
-- copy the file to the destination
duplicate file source to folder destination with replacing
-- calculate the new file path
set fileName to name of file source
if destination does not end with ":" then set destination to destination & ":"
set newPath to destination & fileName
-- rename the copied file
set name of file newPath to "Newname.MOV"
end tell
end open