Script seemingly keeps running after it has done its job

Hello,

I have written a script that I attached as a folder action to do some basic file moving and storage for my business. This script works on most of my machines without error. However, I have just installed it on a new machine and after the script has finished its job, the Finder keeps flashing as if the script is still trying to act. I am pasting my script up here in hopes that someone can help me with this error. Also, if anyone knows of a trace command within AppleScript, that would be helpful to know.

property dxf_list : {"dxf"}
property jpg_list : {"jpg"}

(*This sets up lists that include any file with the name or extension that includes dxf or jpg*)

on adding folder items to this_folder after receiving these_items
	
	tell {current date}
		copy beginning to end
		set end's month to January
		tell ((beginning's year) * 10000 + (beginning - (end - 3944592)) div 2629728 * 100 + (beginning's day)) as string
			text 5 thru 6 & "/" & text 7 thru 8 & "/" & text 1 thru 4
			set current_date to the result
		end tell
	end tell
	
	(*This sets up a variable to tell us the current day's date in the format of xx/xx/xx*)
	
	try
		repeat with i from 1 to number of items in these_items
			set this_item to item i of these_items
			set the item_info to the info for this_item
			if the name extension of the item_info is in the dxf_list then
				tell application "Finder"
					display dialog "Which plant is this order going to?" buttons {"TN", "NH", "Cancel"} default button 3
					set the Plant_Location to the button returned of the result
				end tell
				if the Plant_Location is "TN" then
					tell application "Finder"
						move files of folder "Endless Cutplans" of folder "Desktop" of folder "USERS HOME FOLDER" of folder "Users" of startup disk to folder "to be organized_TN" of disk "Projection_Cutplans"
						tell application "Finder"
							delete these_items
						end tell
					end tell
				else
					tell application "Finder"
						
						move files of folder "Endless Cutplans" of folder "Desktop" of folder "USERS HOME FOLDER" of folder "Users" of startup disk to folder "to be organized_NH" of disk "Projection_Cutplans"
					end tell
					tell application "Finder"
						delete these_items
					end tell
				end if
			else
				if the name extension of the item_info is in the jpg_list then
					tell application "Finder"
						try
							make new folder at folder "Endless CP to print" of disk "Projection_Cutplans" with properties {name:current_date}
							move files of folder "Endless Cutplans" of folder "Desktop" of folder "USERS HOME FOLDER" of folder "Users" of startup disk to folder current_date of folder "Endless CP to print" of disk "Projection_Cutplans" with replacing
						on error
							move files of folder "Endless Cutplans" of folder "Desktop" of folder "USERS HOME FOLDER" of folder "Users" of startup disk to folder current_date of folder "Endless CP to print" of disk "Projection_Cutplans" with replacing
						end try
						
					end tell
				end if
				tell application "Finder"
					delete these_items
				end tell
			end if
		end repeat
	on error
		tell application "Finder"
			display dialog "Error!"
		end tell
	end try
end adding folder items to

--written by Brian Keith Eibert 4/7/06; modified 1/17/08

Thanks, Brian

It is probably trying to display the on error dialog – you’ve asked the Finder to do it. You might tell “System Events” instead or click on the Finder to find out why it’s bouncing.

Thanks for your reply.

The Finder icon is not bouncing, the menu bar at the top of the screen is flashing. I believe it has something to do with the delete items section of the script. I tried to place a timeout function within the script and that didn’t work. I will change it to try the System Events idea and see if that changes anything.

Thanks, Brian

Model: G4, 1.25 GHz, 512 MB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi,

maybe the problem is,
the script uses a loop to process each single item but deletes all added items at the end of the repeat block.

PS: the amazing routine to get the formatted date can be written easier with

set current_date to do shell script "date +%m/%d/%Y"

Thanks Stefan!

I am going to try to comment out the delete at the end and see if that helps. Also, thanks for the help on the current_date variable. I can’t claim credit for the current version which I borrowed from another script writer and made some slight modifications to get what I wanted. I am betting yours will work much better (not to mention it saves me a lot of typing time)

Thanks, Brian

Model: G4, 1.25 GHz, 512 MB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hello Again,

I have made those changes and have found that, on my machine, I can make many different changes and I do not get any weirdness (the menu bar flash as if it is trying to re-delete files), including changing when and how often I delete the items in the folder. However, when I move the exact same script (modified to work with other users folders of course) to another machine, I get the odd results. I know that I have had this issue in the past and have fixed it at one time (note to noob script programmers like myself DOCUMENT, DOCUMENT, DOCUMENT) but alas I cannot recall how I fixed the issue. If and when we arrive at a solution, I’ll be certain to post it here, as well as write it down for posterity in my notebook.

Thanks, Brian

Model: G4, 1.25 GHz, 512 MB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

It’s a joke routine from my “DateTips” package in ScriptBuilders: a flamboyant exercise in achieving the end without using any variables. :wink: Part of the calculation with the two dates in the list is a variant of Emmanuel Lévy’s “French Vanilla” method for getting the month of a date as a number, not needed since month-to-integer coercions were introduced in Panther. The rest of it’s a fast, vanilla method for adding the leading zeros.

set now to (current date)
set {year:y, day:d} to now
copy now to b
set b's month to January
set m to (b - 2500000 - now) div -2500000
-- Easier to remember than (now - (b - 3944592)) div 2629728
-- and not affected by a long-standing bug that was only cured in Tiger.

tell (y * 10000 + m * 100 + d) as string
	set US_short_date to text 5 thru 6 & "/" & text 7 thru 8 & "/" & text 1 thru 4
end tell

With regard to beibert’s actual problem, I can’t see the logic in dropping items (assumed to be files) into one folder so that their name extensions will cause files to be moved or copied between two others. Is the drop folder one of the folders mentioned by name in the script? What’s the script supposed to do, exactly?

I’m not seeing any obvious problems. As far as debugging/troubleshooting, you have a lot of “try” loops going on. I would comment out all of the try/on error lines and run it to see what specific errors you get. Your script may be erroring every time you run it but you are indicating to ignore those errors.

Model: G5 OSX 10.4.8
Browser: Safari 419.3
Operating System: Mac OS X (10.4)