odd behavior from a script

hmmm. i could see what you’re saying. that ‘could’ be a problem, but theFile1 will never be on the same machine as fileLoc. the server drive is a faceless machine. so, that won’t be an issue here.

You may try this version.

As network is involved I can’t test it as a whole.

set uName to "**USERNAME_HERE**"
set pass to "**PASSWORD_HERE**"

set p2Desktop to path to desktop as text # Defined only once
tell application "System Events"
	if not (exists folder (p2Desktop & "Database")) then
		set mount1_conn to false
		set loopcount to 1
		repeat until mount1_conn is true or loopcount is greater than 3
			if exists folder (p2Desktop & "DRIVENAME") then
				set mount1_conn to true
			else
				try
					mount volume "afp://SERVERNAME.local/DRIVENAME" as user name uName with password pass
				end try
				delay 1
				set loopcount to loopcount + 1
			end if
		end repeat
	end if #  not exists folder
	
	set terminalID to "**IDNUMBER**" # no need to coerce a string as string
	set fileName to terminalID & "_1.jpg" # no need to coerce a string as string
	set fileLocText to "DRIVENAME:FOLDERNAME:SUBFOLDERNAME:"
	set fileLoc to fileLocText as alias
	if not (exists file (fileLocText & fileName)) then
		set theFile1 to (choose file with prompt "Select Picture To Import")
		# Here theFile1 and fileLoc are aliases
		set fileExtension to name extension of theFile1
		# Here theFile1 and fileLoc are aliases
		if fileExtension is in {"jpg", "jpeg"} then #  EDITED because there is no need to convert a jpeg into a JPEG file
			try
				--set fileName1 to name of theFile1 # Here fileName1 is a string but it's unused !
				--set nameWithoutExtension1 to terminalID & "_1"
				--set newName1 to nameWithoutExtension1 & ".jpg"
				set newName1 to terminalID & "_1.jpg" # This single instruction does the job
				set name of theFile1 to newName1
				# Now theFile1 is an awful monster like : alias "/Users/<theAccount>/Desktop/ligne droite.jpeg"
			end try
					set path2File1 to path of theFile1 # it's a string
			move theFile1 to fileLoc # ADDED
			# When System Events moves a file from and to local devices
			#  the original is no longer in its original location, so there is no need to trash it.
# You said that it behaves differently with networks
# With the added instructions it will work in both cases
try
				delete disk item path2File1 # ADDED
			end try
		else
			tell application "SystemUIServer" to display alert "This is not a jpg file.  You will need to convert it before you add it to the database.  Press 'OK' to convert the file."
			tell application "System Events" # I leave it but I'm quite sure that it is useless
				# Here theFile1 and fileLoc are aliases
				--set this_file to theFile1 # Useless according to the change made below
				
				set the target_path to p2Desktop & fileName # This single instruction does the job
				try
					tell application "Image Events"
						launch
						--set this_image to open this_file
						set this_image to open theFile1
						save this_image as JPEG in target_path with icon
						close this_image
						quit # REQUIRED. without it next run would fail
					end tell
				on error errMsg number errorNumber
					tell application "System Events"
						if "Image Events" is in name of every process then quit application "Image Events"
					end tell
					tell application "SystemUIServer" to display dialog "An unknown error occurred:  " & errorNumber & " - " & errMsg as text
				end try
				set thePath to path of theFile1 # it's a text object
				set imagePath1 to thePath & fileName # Here, imagePath1 is a string
				move disk item imagePath1 to fileLoc
			# When System Events moves a file from and to local devices
			#  the original is no longer in its original location, so there is no need to trash it.
			end tell # System Events # I leave it but I'm quite sure that it is useless
				try
					delete disk item imagePath1 # ADDED
				end try
		end if # not (exists file fileName
	end if
end tell # System Events

You will be free to remove the disabled instructions if everything behave well.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mardi 15 septembre 2015 22:47:18

great, i’ll give that a shot. but, the part where you have : “# When System Events moves a file, the original is no longer in its original location”, that’s not the case. when moving a file to a mapped drive, it doesn’t actually move it, it copies it. so the original still stays on the desktop (or wherever it was originally)

I don’t use networks so I can’t test such case.

In my late message I added 7 instructions allowing the script to work well in both cases.

When I test the subsets of the code on my local machine, there is nothing to delete and the try / end try instructions get rid of that.
On a machine using networks, if the source file remains, it will be deleted which is more efficient than moving to the trash.
If you prefer to retrieve the file in the trash,
replace :
delete disk item path2File1
by
move disk item path2File1 to the trash

and

replace :
delete disk item imagePath1
by
move disk item imagePath1 to the trash

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 16 septembre 2015 12:07:48

awesome. thanks again!

Thanks for the feedback.
I made a small change.

As the handler GetParentPath was called by a single instruction, I dropped it and edited the caller accordingly.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 16 septembre 2015 14:40:43