AS not working since move to Monterey

Hi all

I have the below script which has been running perfectly well on my old iMac running Mojave but have since I’ve upgrade to an MBP using Monterey 12.1 it has stopped working with an error message.

The error I’m getting is:

“Can’t make file 1 of «class cfol» “Previous Versions” of «class cfol» “FOLDER NAME” of «class cfol» “Desktop” of «class cfol» “g-uk-tam1-retail-2” of «class cfol» “Users” of «class sdsk» of application “Finder” whose «class nmxt» of it = “ai” into type alias. (-1700)”

Any ideas why it’s failing here? Is it a path thing?
Any tips greatly received.

And this is my script:



on open theDroppedItems -- parent folder dropped here starts the script (after prepping artwork in Illustrator manually)
	
	set parentFolder to item 1 of theDroppedItems -- result: alias
	tell application "Finder"
		set parentFolder to folder (parentFolder as text) -- result: Finder reference, ADDED
		tell parentFolder to set childFolder to folder 1 -- result: Finder reference, EDITED
		tell childFolder to set theAi to (first file whose name extension is "ai") as alias -- result: alias
	end tell -- this block sets up the file/folder structure into variables for later referencing in the script
	
	-- illustrator actions below
	
	tell application "Adobe Illustrator"
		activate
		open theAi -- opens the Illustrator file from the sub Artwork folder
		delay 1.0
		do script "APPROVED" from "RELEASES" -- runs the specific Illustrator action
	end tell
	
	-- illustrator actions above
	
	
	-- dialog to wait for PDF to be distilled before continuing
	
	tell application "Finder"
		activate
		
		set r to display dialog "Release the file?" buttons {"Yes", "No"} default button "Yes" giving up after 10 -- seconds
		if r's gave up or r's button returned is "Yes" then
			
			
			-- do stuff here....
			
			
			tell application "Finder"
				repeat
					try
						alias "Dave's Mac:Users:g-uk-tam1-retail-2:Desktop:PDF's:FOR RELEASES:" -- does the distilled file exists? This section checks to see if the new approved PDF has been created and is in the "FOR RELEASES" folder (where the Illustrator Action ultimately saves the PDF)
						
						tell application "Finder"
							
							set a to "Dave's Mac:Users:g-uk-tam1-retail-2:Desktop:PDF's:FOR RELEASES:" as alias
							duplicate files of entire contents of a to childFolder with replacing
							
							
						end tell
						
						-- if the approved PDF file is ready in the FOR RELEASES folder the above instruction moves the PDF to the sub Artwork folder overwriting the old "unapproved" file. If it is not present the script does not move on. Be aware that the script will pause indefinitely until the file is present - running this workflow again without the previous workflow completing may result in unexpected results. In summary - the PDF must be present or you will need to Force Quit the workflow.
						
						tell application "MakeZipOnly" -- this is an Automator process
							activate
							open childFolder
						end tell
						exit repeat
					end try
					delay 1
					--delete files of entire contents of a -- this removes the Approved PDF from the FOR RELEASES folder after it has been "moved" ("move" doesnt seem to move but "copies")
					
				end repeat
				
				-- the above block activates an Automator application to zip file (need to figure out how to do this in Applescript to make this self contained - although all on-line references point to this being incredibly complex - Automator makes this section easy
				
				tell application "Finder"
					set a to "Dave's Mac:Users:g-uk-tam1-retail-2:Desktop:PDF's:FOR RELEASES:" as alias
					set b to "Dave's Mac:Volumes:TamworthMacRAID:TEMPORARY FILE TRANSFERS:RELEASES:PDF's:" as alias
					move files of entire contents of a to b with replacing
				end tell -- this sets up the variables and copies the PDF over that will need to go to Aldi monthly 
				
				delay 1
				delete files of entire contents of a -- this removes the Approved PDF from the FOR RELEASES folder after it has been "moved" ("move" doesn't seem to move but "copies")
				
				
			end tell
			
			
			
			-- the following is a block to attach the zip file to an email after all above done.
			
			tell application "Finder"
				set NameOfFile to (name of (info for theDroppedItems))
				set NameOfFile to text 1 thru ((offset of "." in NameOfFile) - 1) of NameOfFile
				set myFile to childFolder as alias
				--this sets up the folder variables ready for the Outlook email code below
			end tell
			
			--the below code attaches the file to an email with the details as below
			
			tell application "Microsoft Outlook"
				set mySubject to NameOfFile & " APPROVED FILE RELEASE" as text
				set myContent to "<p style=font-family:Calibri>-</p><p style=font-family:Calibri>Attached is the Approved Release File for " & NameOfFile & "<p style=font-family:Calibri>Thanks</p>"
				set myAttachment to childFolder
				set myMsg to make new outgoing message with properties {subject:mySubject, content:myContent}
				tell myMsg
					make new attachment with properties {file:myFile}
					make new recipient with properties {email address:{name:"Dave Leicester", address:"aldisrp.tamworth@smurfitkappa.co.uk"}}
					
				end tell
				
				open myMsg
				
				
			end tell
			
			-- the below code renames the Parent (main job) folder prefixing it with "RELEASED"
			
			set a to theDroppedItems
			tell application "Finder"
				set folderName to name of folder a
				set folder a's name to "RELEASED " & folderName
			end tell
			
		end if
		
	end tell
	
end open

(Missing [/applescript] tag added by NG.)

Hi.

I don’t have Monterey, but the first thing to check would be that there is actually a file with the name extension “ai” in the child folder. Also that the intended child and parent folders are the ones the script finds.

Not apparently connected with your problem, but your second tell application “Finder” statement contains nested tell statements to the Finder and other applications. This isn’t generally considered a good idea, both from the point of view of legibility and the possibility of terminology conflicts.

Also:

info for isn’t a Finder command and it’s been deprecated for a while now. Its parameter is a single alias or file specifier, but ‘theDroppedItems’ is the list containing the dropped items. However, it’s probable that info for is still available in Monterey, and AppleScript usually treats single-item lists as the items themselves, so the line should still work provided only one item is dropped at a time. Then again, since you already have a Finder reference to the item in your ‘parentFolder’ variable, it would be better to use that:

tell application "Finder"
	set NameOfFile to (name of parentFolder)

@TheBlackBinLiner

1)You don’t need to call the Finder multiple times in the same call block
2) specify path a and path b once and on top, instead to repeat yourself
3) Also try to use (path to desktop)
4) experiment with handlers instead to put all your code in one monstrous shape, so you’ll get a better understanding how to elaborate better all the steps important to you. This will help you to debug and clean up things, in a better and faster running code