I have found a script that allows me to duplicate and file and then rename it but I keep getting an error (error number -10010) the person who made the code just had a dialogue box show up saying an error occurred.
Here is the code:
set TheFile to POSIX file "/Users/server/Desktop/backup_info/Backup log full/full_backup_log.rtf" as text
set DestinationPath to POSIX file "/Users/server/Desktop/backup_info/Backup log full/October/9/" as text
set destinationFilename to ((current date) as text) & ".rtf"
with timeout of 600 seconds
tell application "Finder"
try
set theDupe to duplicate TheFile to folder DestinationPath
set name of theDupe to destinationFilename
on error
display dialog "Oops, a problem occurred duplicating the file."
end try
end tell
end timeout
This is going into a script that creates folders based on the month and day it will either create the folders or move and rename a backup log file.
is there something I am doing wrong? I have tried removing the POSIX file and replacing “/” with “:” and removing as text and I still seem to get the error.
You should be able to see an error message in the events pane in Applescript Editor if you run your script from there, that may give you a clue about what is wrong.
To me it seems like it may work if you remove the coercions to text, (as text).
You may also insert various log statements at various places, in order to figure out what is wrong, or where it did go wrong.
here is the events/replies from the log at the bottom:
tell current application
current date
--> date "Thursday, 9 October 2014 10:43:50"
end tell
tell application "Finder"
copy "Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf" to folder "Server:Users:server:Desktop:backup_info:Backup log full:October:9:"
--> error number -10010
display dialog "Oops, a problem occurred duplicating the file."
--> {button returned:"OK"}
end tell
Result:
{button returned:"OK"}
set backupLogFullFolder to (path to desktop as text) & "backup_info:Backup log full:"
set theFile to backupLogFullFolder & "full_backup_log.rtf"
set destinationPath to backupLogFullFolder & "October:9:"
set destinationFilename to ((current date) as text) & ".rtf"
with timeout of 600 seconds
tell application "Finder"
try
set theDupe to duplicate file theFile to folder destinationPath
set name of theDupe to destinationFilename
on error e
display dialog "Oops, a problem occurred duplicating the file." & return & e
end try
end tell
end timeout
tell current application
path to desktop as text
--> "Server:Users:server:Desktop:"
current date
--> date "Thursday, 9 October 2014 11:12:45"
end tell
tell application "Finder"
copy file "Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf" to folder "Server:Users:server:Desktop:backup_info:Backup log full:October:9:"
--> error number -1728 from file "Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf"
display dialog "Oops, a problem occurred duplicating the file.
Finder got an error: Can't set folder \"Server:Users:server:Desktop:backup_info:Backup log full:October:9:\" to file \"Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf\"."
--> {button returned:"OK"}
end tell
and @alastor993
I am copying an .rtf file that shouldn’t affect it should it?
the error occurs if the source file (or the destination folder) does not exist
This is a version which creates the folder of current month/day automatically
set backupLogFullFolder to (path to desktop as text) & "backup_info:Backup log full:"
set theFile to backupLogFullFolder & "full_backup_log.rtf"
tell (current date) to set {destinationFilename, currentMonth, currentDay} to {(it as text) & ".rtf", its month as text, its day}
set destinationPath to backupLogFullFolder & currentMonth & ":" & currentDay & ":"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of destinationPath
with timeout of 600 seconds
tell application "Finder"
try
set theDupe to duplicate file theFile to folder destinationPath
set name of theDupe to destinationFilename
on error e
display dialog "Oops, a problem occurred duplicating the file." & return & e
end try
end tell
end timeout
Do I need to change any accessibility settings possibly?
tell current application
path to desktop as text
--> "Server:Users:server:Desktop:"
current date
--> date "Thursday, 9 October 2014 11:34:01"
do shell script "/bin/mkdir -p '/Users/server/Desktop/backup_info/Backup log full/October/9/'"
--> ""
end tell
tell application "Finder"
copy file "Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf" to folder "Server:Users:server:Desktop:backup_info:Backup log full:October:9:"
--> error number -1728 from file "Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf"
display dialog "Oops, a problem occurred duplicating the file.
Finder got an error: Can't set folder \"Server:Users:server:Desktop:backup_info:Backup log full:October:9:\" to file \"Server:Users:server:Desktop:backup_info:Backup log full:full_backup_log.rtf\"."
--> error number -128
Result:
error "Finder got an error: User canceled." number -128
PS: the shell command ditto is able to create intermediate directories, duplicate and rename in one line
set backupLogFullFolder to POSIX path of (path to desktop) & "backup_info/Backup log full/"
set theFile to backupLogFullFolder & "full_backup_log.rtf"
tell (current date) to set {destinationFilename, currentMonth, currentDay} to {(it as text) & ".rtf", its month as text, its day}
set destinationPath to backupLogFullFolder & currentMonth & "/" & currentDay & "/"
do shell script "usr/bin/ditto " & quoted form of theFile & space & quoted form of (destinationPath & destinationFilename)