AS and FMPA runtime fail on build - runtime

OK I have one that doesn't seem to be answered.
I'll past the whole script
The problem is with the TRY. Since it is happening in the Finder and I am trying to pass some info back to FM. THis works fine as a FM script but fails in the runtime. As far as I can tell the only solution would be to change all the Filemaker Pro Advanced references to the runtime app BUT I can't do that because FMPA wants me to show it the app and of course it isn't built yet! So I guess I could build the runtime and then edit IT'S scripts to work. But that seems like a funky workaround. I tried using "me" but I think because it's part of a try still running in the Finder it fails.
-- script to copy files to PT directory 1/21/02
set copysounds to ""
set thetarget to ""
set x to ""
set filename to ""
tell application "FileMaker Pro Advanced"
--activate
set recordCount to count of records
end tell
choose folder with prompt "Pick a destination folder"
set thetarget to result
repeat with x from 1 to recordCount
tell application "FileMaker Pro Advanced"
set copysounds to cell "Find Path" of record x
set effectName to cell "Effect Name:" of record x
set filename to ((thetarget as text) & (cell "Effect Name:" of record x))
set cell "error flag" of record x to ""
set notFoundError to ""
set DupOK to ""
-- find out if file esists
tell application "Finder"
activate
try
alias copysounds
on error
set notFoundError to "true"
display dialog effectName & " file was not found. Check Path." buttons {"OK"} default button 1 with icon stop
tell application "FileMaker Pro Advanced"
set cell "error flag" of record x to "Path Invalid"
end tell
--return
end try

Not having a copy of the database makes it hard for me to test but lets start here. You have allot of things out of place so I fixed up your code
try this
-- script to copy files to PT directory 1/21/02
set copysounds to ""
set thetarget to ""
set x to ""
set filename to ""
set thetarget to choose folder with prompt "Pick a destination folder"
tell application "FileMaker Pro 10"
set recordCount to count of records
repeat with x from 1 to recordCount
set copysounds to cell "Find Path" of record x
set effectName to cell "Effect Name:" of record x
set filename to ((thetarget as text) & (cell "Effect Name:" of record x))
set cell "error flag" of record x to ""
set notFoundError to ""
set DupOK to ""
try
tell application "Finder" to alias copysounds
on error
set notFoundError to "true"
display dialog effectName & " file was not found. Check Path." buttons {"OK"} default button 1 with icon stop
set cell "error flag" of record x to "Path Invalid"
end try
end repeat
end tell

UPDATE: Pardon a simple question, but do you have the database open when you run the script as an application or otherwise. The only way I can get the same "object not found" error in Applescript is if I don't have database open. See the following example...
tell application "FileMaker Pro"
set theRecords to records --> if a database isn't open in Filemaker, this gets an "object not found" error.
return theRecords --> if a database is open, a list of records is returned.
end tell
I can't help but think that something more fundamental than runtimes is being missed here.
As far as I can tell the only solution would be to change all the Filemaker Pro Advanced references to the runtime app BUT I can't do that because FMPA wants me to show it the app and of course it isn't built yet! So I guess I could build the runtime and then edit IT'S scripts to work. But that seems like a funky workaround.
You can save the script as an application and save it so that you can edit it in the Script Editor application. I've done this numerous times before. For debugging, instead of going to the activity viewer, you can write to a file instead and read that when the script is done doing its thing. It's funky but not out of the ordinary for Applescript.
I tried using "me" but I think because it's part of a try still running in the Finder it fails.
mcgrailm's code is much cleaner, but it seems to me you're still going to get an error on the try regardless if you use me or not; trying to get the alias of a file will return an error if the path is incorrect every single time. If the error is here...
try
tell application "Finder" to alias copysounds
on error
...then you need to investigate the value copysounds and how that value is generated. I agree with mcgrailm that sample data from your FM DB would be really helpful here, and so would the exact errors you are getting from the try. Something like this will help capture that...
try
-- insert actions here
on error the error_message number the error_number
-- do something with the strings error_message and error_number
end try

Related

Applescript Tool:Copying files to preset directories based on team member names

I am not a programmer by trade, but an art director on a rather large project where I do many repetitive tasks on a daily basis. One constant is moving files to team member's folders. I want to be able to select some files and have a menu appear for me to choose who will receive the files.
I made some progress but am stuck. The script cannot find the directory I intend the files to go. I fear it has something to do with POSIX paths - or me not defining it as a folder rather than a file? The error reads:
error "File /Volumes/Workbench/Test/CookieMonster wasn’t found." number -43 from "/Volumes/Workbench/Test/CookieMonster"
...even thou there is a folder where it says there isn't. I suspect my syntax is incorrect somehow.
set currentFolder to path to (folder of the front window) as alias
on error -- no open windows
set the currentFolder to path to desktop folder as alias
end try
set artistList to {"CookieMonster", "BigBird", "Bert", "Ernie", "Grouch"}
set assignTo to {choose from list artistList with title "Assign to..." with prompt "Please choose" default items "Bert"}
set assignedArtist to result
set artDeptDir to "/Volumes/Workbench/Test/"
set filePath to {artDeptDir & assignedArtist}
set destinationFolder to filePath as alias
set selected_items to selection
repeat with x in selected_items
move x to folder of filePath
end repeat
If anyone who has insight into my problem, I would love to hear from them. Thank you for taking the time to read this.
The main issue is that the Finder doesn't accept POSIX paths. You have to use HFS paths (colon separated and starting with a disk name).
This version fixes another issue and redundant code was removed
tell application "Finder"
try
set currentFolder to (target of the front window) as alias
on error -- no open windows
set currentFolder to path to desktop
end try
set artistList to {"CookieMonster", "BigBird", "Bert", "Ernie", "Grouch"}
-- no braces {} !
set assignTo to (choose from list artistList with title "Assign to..." with prompt "Please choose" default items "Bert")
if assignTo is false then return
set assignedArtist to item 1 of assignTo
-- no braces {} !
set destinationFolder to "Workbench:Test:" & assignedArtist
move selection to folder destinationFolder
end tell

applescript: how to copy real file instead of alias, but recursively

I am using the following script to copy certain folder content from my hard-drive on a usb-Stick. Since the folder content might change, I am using aliases.
The script used to work perfectly, but since I had to make changes in my folder structure, I now have sometimes an alias of an alias (workaround of the script, won´t go into that).
Problem is that the script seems to only convert the first level of alias-folders, but if there is an alias for a file within an alias for a folder, it copies the file-alias.
I wonder if it is possible to tell the script to recursively go through every level of the folder (ie every file) and copy the original file instead.
Thanks!
Peter
ps: exemplary folder structure of source folder:
alias of folder 1
alias of folder 1-1
alias of file a, alias of file b
alias of folder 2
alias of file c
--> first a dialogue
display notification "hello, get folder ready"
delay 5 --> allow time for the notification to trigger
set theDialogText to "choose source"
display dialog theDialogText
--> Result: {button returned:"OK"}
--> now computing
set the backupSource to (choose folder) as alias
set theDialogText to "choose destination"
display dialog theDialogText
--> Result: {button returned:"OK"}
set the backupDestination to (choose folder) as alias
display notification "maybe this takes a while..."
delay 6 --> allow time for the notification to trigger
--> now copy
tell application "Finder"
activate
with timeout of 600 seconds --> equeals 10 Minutes
set everyAlias to every item of folder backupSource
repeat with thisAlias in everyAlias
set originalFile to (original item of thisAlias)
duplicate originalFile to backupDestination
end repeat
end timeout
end tell
``````````
I feel that the the line "repeat thisAlias in everyAlias" doesn´t do its job and goes only one level down, ie it converts the alias on the first level and not all other aliases within this alias-folder
I don't have a quick fix, but rather programming advice: it's time to add debugging. In this case, I suspect your script is not operating on the files you intend to use. So what's it doing instead?
For example, near the beginning,
set debugOn to true
or better
property debugOn : true
Then right before your duplicate command,
if debugOn then display dialog ¬
"Copying thisAlias: " & return & (thisAlias as text) & return & ¬
"of originalFile: " & return & originalFile buttons "OK" default button 1
…and so forth. You can leave these if debugOn then… checks throughout your code with dialogs or even different modes of behavior, and just change it to property debugOn : false once it's working. Having it all there is also great for the inevitable day you need to edit the script, but it's aged enough you've forgotten all its nuances.
Maybe this following AppleScript code will help you accomplish what you're looking for?
tell application "Finder"
set sourceFolder to choose folder with prompt "CHOOSE SOURCE"
set destinationFolder to choose folder with prompt "CHOOSE DESTINATION"
set nestedFolders to a reference to (entire contents of sourceFolder)
set aliasFiles to a reference to every alias file of nestedFolders
set aliasFiles to contents of aliasFiles
repeat with i from 1 to count of aliasFiles
set thisItem to item i of aliasFiles
if not (exists of original item of thisItem) then
delete thisItem
end if
end repeat
set aliasFiles to a reference to every alias file of nestedFolders
set originalFiles to (original item of aliasFiles) as alias list
duplicate originalFiles to destinationFolder
end tell

Error when trying to duplicate files to shared server

I'm trying to get duplicate home folders (desktop, movies, music, home, etc..) to a shared server. I was finally able to get the drive mounted using a concatenation of string and variables. But now i'm getting an error on the duplication line. If I mount the drive manually, this code works, but doesn't seem to work when mounting the drive through applescript
--Assigns variable to username
tell application "System Events"
set user_name to name of current user
end tell
--Prompts for eraider as string
set returnedName to (display dialog "Enter Raider Name:" default answer "eRaider" buttons {"Continue"} default button 1 giving up after 5)
--Sets string as variable
set work_name to text returned of returnedName
--Sets department list
set deptList to {"dept1", "dept2", "dept3", "dept4"}
set dept_name to {choose from list deptList} as string
--Tells Finder to mount shared drive
tell application "Finder"
mount volume ("smb://vserver/athletics/"&dept_name&"/"&work_name)
end tell
--Sets sever as variable
set vserver to POSIX file ("/Volumes/" & work_name)
--Copies Documents to Server
set source to POSIX file ("/Users/" & user_name & "/Documents")
tell application "Finder"
duplicate source to vserver with replacing
end tell
I get this error
error "Finder got an error: AppleEvent handler failed." number -10000
On this line: duplicate source to vserver with replacing
You have a few strange things in your code. Most of them do not affect your error however they should be corrected. For example the "mount volume" command is not a Finder command, it's an applescript command and thus you should not tell the Finder to perform that command. Next, the "choose file" line... why do you have brackets around it? Plus other small things. So I cleaned up the code.
To get to your specific problem it could be 2 things. First, I use an if statement to ensure the disk is mounted before trying to duplicate the files. Second, the "POSIX File" command could also cause problems. It's an unusual command in that it doesn't always work the way you expect. Therefore in this code, to ensure we avoid any issues with that command, I coerce it to text and then in the duplicate command I put it in the proper format by using the word "folder" in front of it.
So I did not test this code but it should work. I hope it helps.
--Assigns variable to username
tell application "System Events" to set user_name to name of current user
--Prompts for eraider as string
set work_name to text returned of (display dialog "Enter Raider Name:" default answer "eRaider" buttons {"Continue"} default button 1 giving up after 5)
--Sets department list
set deptList to {"dept1", "dept2", "dept3", "dept4"}
set dept_name to item 1 of (choose from list deptList)
--mount shared drive
mount volume ("smb://vserver/athletics/" & dept_name & "/" & work_name)
if work_name is in (list disks) then
--Copies Documents to Server
set source to (POSIX file ("/Users/" & user_name & "/Documents")) as text
tell application "Finder" to duplicate folder source to disk work_name with replacing
else
display dialog "Disk " & work_name & " is not mounted"
end if
An even better way would be to use the "path to" command to establish the path to your documents folder. This way you don't need to use "POSIX File" or even know the user name because the "path to" command automatically works for the current user. Plus I would do a little more error checking on the mount volume stuff. So really this is how I would write your code... I didn't test this either!
--Prompts for eraider as string
set work_name to text returned of (display dialog "Enter Raider Name:" default answer "eRaider" buttons {"Continue"} default button 1 giving up after 5)
--Sets department list
set deptList to {"dept1", "dept2", "dept3", "dept4"}
set dept_name to item 1 of (choose from list deptList)
--mount shared drive
set isMounted to false
if work_name is not in (list disks) then
mount volume ("smb://vserver/athletics/" & dept_name & "/" & work_name)
-- wait for the volume to be mounted but only wait for a limited time before failing (10 seconds in this case)
set inTime to current date
repeat
delay 0.2
if work_name is in (list disks) then
set isMounted to true
exit repeat
end if
if (current date) - inTime is greater than 10 then exit repeat
end repeat
else
set isMounted to true
end if
--Copies Documents to Server
if isMounted then
set source to path to documents folder
tell application "Finder" to duplicate source to disk work_name with replacing
else
display dialog "There was an error mounting disk " & work_name buttons {"OK"} default button 1
end if

OSX: How can check whether a file exists in current directory using applescript?

I want to make an automator app which creates an empty file in current directory.
I did some google search and found:
http://hints.macworld.com/article.php?story=20050219134457298 and http://hints.macworld.com/article.php?story=20100509134904820
However, I want to do something more powerful.
If the specified file already exists, I want to show a warning instead of overwriting the original file, which is what one of the above link does. (The other one creates a text file using textEdit. I do not want to create text file. I want an empty file like what linux/unix does)
I already figured out how to do most of the part, but
How can check whether a file exists in current directory using applescript??
How can I concatenate two variable in applescript?
Checking if a file exists (assuming thefullpath is already set as in the referenced question):
tell application "Finder"
if exists POSIX file thefullpath then
--do something here like
display alert "Warning: the file already exists"
end if
end tell
Not sure what you mean by the second part but if you want to concatenate strings stored in var1 and var2 you could simply do
var1 & var2
Something I have been using a lot of late for this sort of thing is the command /bin/test
The test test for the existence of in this case a file
if (do shell script "/bin/test -e " & quoted form of (POSIX path of theFile) & " ; echo $?") is "1" then
-- 1 is false
--do something
end if
The -e option:
-e file True if file exists (regardless of type).
The are tons of other test options shown in the /bin/test man page
The following code, adapted from your second link, is usually right, but it doesn't always work. The current directory is better specified as the directory of the document that is being opened which is most likely from the Finder's front window, but not necessarily. I like to write code that will work no matter what.
on run {input, parameters}
tell application "Finder"
set currentPath to insertion location as text
set x to POSIX path of currentPath
display dialog "currentPath: " & (x as text)
end tell
return x
end run
I wrote a whole "Run AppleScript" action to put things into context:
on run {input, parameters}
# count the number of files
set numFiles to 0
repeat with f in input
# warn the user that folders are not processed in this app
tell application "Finder"
if (kind of f is "Folder") then
display dialog "The item: " & (f as text) & " is a folder. Only files are allowed. Do you want to continue processing files or do you want to cancel?"
else
set numFiles to numFiles + 1
end if
end tell
end repeat
# require that at least one file is being opened
if numFiles < 1 then
display alert "Error: the application Test1.app cannot be run because it requires at least one file as input"
error number -128
end if
# get the current directory from the first file
set theFirstFile to (item 1 of input)
tell application "System Events" to set theFolder to (container of theFirstFile)
# ask the user for a file name
set thefilename to text returned of (display dialog "Create file named:" default answer "filename")
# create the file
tell application "System Events" to set thefullpath to (POSIX path of theFolder) & "/" & thefilename
set theCommand to "touch \"" & thefullpath & "\""
do shell script theCommand
# return the input as the output
return input
end run
The "touch" command is OK. If the file doesn't exist, it is created and if it does exist, only the modification date is changed (which isn't too bad) but it doesn't overwrite the file. If your file is being overwritten, it's not the touch command that is doing it.
I changed the default file name to remove the extension ".txt" This extension may default to being opened by TextEdit.app, but you can change this in the Finder by choosing "Get Info" for a file and changing the "Open With" property. You can change which application opens the file with that extension or you can change them all. For example, all of my ".txt" files are opened with BBEdit.app
Will you vote my answer up?
Another option that doesn't require Finder or System Events is to try to coerce a POSIX file or file object to an alias:
try
POSIX file "/tmp/test" as alias
true
on error
false
end try

Applescript copy files to mounted volume; test for file(s) already exists

I am writing a script to allow students to upload their files to a shared folder on teacher's computer in a computer lab (same network). I have a working script that, when executed, will duplicate all files in the folder UPLOAD on the student machine to the folder SUBMISSIONS on the teacher's machine. However, if a file already exists on the teacher machine, the script hangs.
I need to be able to test for the presence of individual files on the teacher machine and either (a) pop a message that says "this file already exists, rename it and upload again" or (b) append something to the file name to differentiate it...a random number or "copy 1" etc.
Ideally I want it to run as a folder action. When a file is added to the "UPLOAD" folder it will automatically be sent to the teacher. But I don't want files to copy over files of the same name...or for the script to hang.
Any thoughts or alterative approaches would be welcome.
Here's my code:
set home_path to path to home folder as string
set work_folder to alias (home_path & "Desktop:" & "Upload")
try
mount volume "afp://[LOGIN INFO].local/Submissions"
set this_folder to result as alias
tell application "Finder"
tell application "Finder"
duplicate every file of work_folder to this_folder
end tell
eject this_folder
end tell
end try
I think that it would help if your try-block had an on-error block to inform you about any errors.
try
# try stuff here
j # this will compile but will throw a runtime error and you can see the error
on error error_message number error_number
display alert "Error: " & error_message & return & return & (error_number as text)
end try
OK. I tried again to write some code. Here is my version.
It does a couple of things differently than the code posted by the original poster.
It copies the files and folders into a new folder on the server with a time-stamp to cope with the problems of whether some of the files already exist on the server.
I changed the wording of the duplicate statement from duplicating every "file" to duplicating every "item" so that folders are duplicated too.
I put in an on-error block in the try-statement to display any errors.
I activate Finder so that you can see the progress window.
I pop up a dialog at the end if there were no errors.
I had a problem that I had to fix:
On the server, I had to enable write permissions for the client or I got a -5000 error.
I think that the following code should work pretty well. It's almost 100% AppleScript. It only uses one call to the shell and that is to get the current date and format it for the time-stamp for new folders created on the server.
# set the path to the "work_folder" where the files are to be uploaded
set home_path to path to home folder as string
set work_folder to alias (home_path & "Desktop:" & "Upload")
# duplicate the files and folders in work_folder to the server
try
# TODO set the name of your server here
set the_volume to mount volume "afp://32-bit.local/Submissions"
set destination_path to the_volume as text
set folder_name to getTimeStamp()
tell application "Finder"
activate
set new_folder to make new folder at alias destination_path with properties {name:folder_name}
duplicate every item of work_folder to new_folder
eject the_volume
display alert "Successfully uploaded the files and folders"
end tell
on error error_message number error_number
if error_number is not equal to -128 then
display alert "Error: " & error_message & return & return & (error_number as text)
end if
end try
# This function returns the current date and time as a time-stamp of the form yyyy-mm-dd-hh-ss
# This function uses a shell script because it's just a lot easier to do than in AppleScript
on getTimeStamp()
set time_stamp to do shell script "date '+%Y-%m-%d-%H-%M-%S'"
return time_stamp
end getTimeStamp
Here's another idea for debugging. You can put in calls to "display dialog" to be able to know where your script is failing:
display dialog "Entering script"
set home_path to path to home folder as string
display dialog "home_path: " & home_path
set work_folder to alias (home_path & "Desktop:" & "Upload")
display dialog "work_folder: " & work_folder as string
try
mount volume "afp://32-bit.local/Submissions"
set this_folder to result as alias
display dialog "this_folder: " & this_folder as string
tell application "Finder"
display dialog "Inside of the first tell application Finder"
tell application "Finder"
display dialog "About to call duplicate"
duplicate every file of work_folder to this_folder
display dialog "Just returned from calling duplicate"
end tell
display dialog "About to call eject"
eject this_folder
display dialog "Just returned from call to eject"
end tell
on error error_message number error_number
display alert "Error:" & error_message & return & return & (error_number as text)
end try
display dialog "Exiting script"
Another debugging technique is to log output to a text file.
Another debugging technique is to purchase the AppleScript debugger:
http://www.latenightsw.com/sd4/index.html
I believe that this debugger costs $200.00 that's too pricey for me, but I've used other debuggers and debuggers are wonderful tools that let you "peek inside" of your script while it's running to see the value of variables and to trace which lines of code are being executed.
This script will copy each file over to the mounted volume. If a file exists with the same name at the destination it will add a number to the end of the copy file name and try that.
Example:if test.doc exists in the folder already then the script will try and copy it with the name test_1.doc and so on..
The original file is never renamed and the older files are never overwritten.
The script is fully commented to explain what it is doing.
** Update2 **
The copy to destination code is now in it's own handler.
The original files are labeled by the finder label index 6 (green) to indicate successful copied.
This will also stop the same original file from being copied twice by using the index colour as a check. If it is labeled index label 7 it will be ignored.
You could if you want move the successful copied files to another folder out of the way using the script. But I have not done this in this script.
set home_path to path to home folder as string
set work_folder to alias (home_path & "Desktop:" & "Upload")
set counter to ""
global counter
--try
set this_folder to mount volume "afp://myMac/UserName/"
this_folder as text
tell application "Finder" to set theFiles to every file of work_folder as alias list #GET ALL FILES OF LOCAL FOLDER AS ALIASES
tell application "Finder" to set theRemoteFiles to (every file of ((this_folder & "Submissions:" as string) as alias)) #GET ALL FILES OF REMOTE FOLDER -- ONLY NEEDED FOR COUNT CHECK LATER
repeat with i from 1 to number of items in theFiles #PROCESS EACH LOCAL FILE
set this_item to item i of theFiles #GET A LOCAL FILE
tell application "Finder" to set LabelIndex to label index of this_item
if LabelIndex is not 6 then
tell application "Finder" to set this_name to displayed name of this_item #GET ITS DISPLAYED NAME
tell application "Finder" to set this_extension to name extension of this_item #GET ITS EXTENSION NAME i.E "txt"
set realName to (do shell script "echo " & quoted form of this_name & "| awk -F '" & quoted form of this_extension & "' '{print $1}'") #GET ITS NAME WITHOUT EXTENSION NAME
set counter to 1 # SET A NUMBER TO ADD TO THE FILE NAME IF THE FILE NAME EXIST ALREADY IN THE REMOTE FOLDER
my checkName(this_name, realName, this_item, this_extension, theRemoteFiles, this_folder) # CALL TO HANDLER THAT WILL DO THE CHECKING AND COPYING
end if
end repeat
tell application "Finder" to eject this_folder
# THE CALL TO THE HANDLER INCLUDES VARIABLES THAT ARE NOT GLOBAL OR PROPERTIES BUT NEED TO BE PASSED ON TO IT I.E(this_name, realName, this_item, this_extension, theRemoteFiles, this_folder)
on checkName(this_name, realName, this_item, this_extension, theRemoteFiles, this_folder)
# (1) IF THE NUMBER OF theRemoteFiles IS GREATER THAN 0 THEN FILES EXIST IN THE REMOTE FOLDER AND MAY CONTAIN FILES WITH THE SAME NAMES AS THE LOCAL ONES. PROCESS..
# (2) IF THE NUMBER OF theRemoteFiles IS NOT GREATER THAN 0.THEN FILES DO NOT EXIST IN THE REMOTE FOLDER AND THE LOCAL ONES CAN JUST BE COPIED OVER.
if (count of theRemoteFiles) is greater than 0 then # (1)
try
my copyOver(this_item, this_folder, this_name)
on error errMssg #WE USE not overwritten ERROR TO TRIGGER THE RENAME THE DESTINATION FILE NAME TO INCLUDE A NEW NUMBER.
--tell application "Finder" to set label index of this_item to 6
if errMssg contains "not overwritten" then
set this_name to (realName & counter & "." & this_extension)
set counter to counter + 1 #WE SETUP THE FILE NAME NUMBER FOR THE POSSIBLE NEXT RUN
# RUN THE HANDLER AGAIN WITH THE CHANED DETAILS
my checkName(this_name, realName, this_item, this_extension, theRemoteFiles, this_folder)
end if
end try
else # (2)
my copyOver(this_item, this_folder, this_name)
end if
end checkName
on copyOver(this_item, this_folder, this_name)
# THE -n OPTION IN THE SHELL COMMAND TELLS CP NOT TO OVERWRITE EXISTING FILES. AN ERROR OCCURE IF THE FILE EXISTS.
# THE -p OPTION IN THE SHELL COMMAND TELLS CP TO PRESERVE THE FOLLOWING ATTRIBUTES OF EACH SOURCE FILE IN THE COPY:
# modification time, access time, file flags, file mode,
#user ID, and group ID, as allowed by permissions. Access Control
#Lists (ACLs) and Extended Attributes (EAs), including resource
#forks, will also be preserved.
# THE -v OPTION IN THE SHELL COMMAND TELLS CP TO USE VERBOS MODE. WHICH GIVES US A BETTER CLUE OF THE ERROR
set theResult to (do shell script "cp -npv " & quoted form of (POSIX path of this_item) & space & quoted form of (POSIX path of (this_folder & "Submissions:" as string) & this_name))
if theResult contains "->" then
tell application "Finder" to set label index of this_item to 6
else
tell application "Finder" to set label index of this_item to 7
end if
end copyOver

Resources