Problem with if-else logic in folder action script

The answer to this question is probably obvious to any experienced scripter, but I can’t guess what it is.

I am writing a folder action script that processes files written to disk by the DOSBox MS-DOS emulator, with the old WordPerfect for DOS program running inside it. A brief description and download link is here:

http://www.wpuniverse.com/vb/showthread.php?s=&threadid=32016

I am now trying to add a routine to the folder action script that gets the name of the current default printer when a file named WHICHPTR.TMP is added to the folder. I already have a routine that tests for files with names like GETCLIP.TMP etc.), but when I add an if-end if block to test for WHICHPTR.TMP, then the other tests stop working. I want to be able to test for at least three different filenames (eventually five or more), and I can’t figure out how to test for more than two.

Here is the start of my script - the part that evaluates the incoming filenames - and I know it’s a bit of a mess, but I would be grateful for any help. There’s a block that’s commented out. The script works with that block commented out, but breaks when I uncomment it. Is there any way to make this work? Many thanks for any help.

-- DOSBoxConvertPrint.scpt 
(*
Heavily modified 3 November 2010 by Edward Mendelson 
from Apple's original convert - PostScript to PDF script
*)

property dosDiskFolder : "DOSDisk"
property doneFolderName : "PDF"
property tempFoldername : "Temp"
property pdfExtension : "pdf"
-- the list of file types which will be processed 
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"} 
property extensionList : {"ps", "tmp"}
property pdfFileNameFile : "WPDOSPDF.PS"
property getClipName : "GETCLIP.TMP"
property sendClipName : "CLIPOUT.TMP"
property getPtrName : "WHICHPTR.TMP"
global namePath
global tempFolder
global outFolderPosix

on adding folder items to thisFolder after receiving theseItems
	set namePath to POSIX path of thisFolder & "PDFNAME.TXT"
	set homePath to (path to current user folder) as string
	set diskPath to (homePath & dosDiskFolder) as alias
	tell application "Finder"
		if not (exists folder doneFolderName of diskPath) then -- was of thisFolder
			make new folder at diskPath with properties {name:doneFolderName}
		end if
		set the resultsFolder to (folder doneFolderName of diskPath) as alias
		if not (exists folder tempFoldername of thisFolder) then
			make new folder at thisFolder with properties {name:tempFoldername}
			set current view of container window of thisFolder to list view
		end if
		set the tempFolder to folder tempFoldername of thisFolder
	end tell
	
	try
		repeat with i from 1 to number of items in theseItems
			set thisItem to item i of theseItems
			set the itemInfo to the info for thisItem
			
			if (the name extension of the itemInfo is in the extensionList) then
				
				if the name extension of the itemInfo is "ps" then
					if (the name of the itemInfo is pdfFileNameFile) then
						tell application "Finder"
							my resolveConflicts(thisItem, tempFolder, "")
							set the newName to my resolveConflicts(thisItem, resultsFolder, pdfExtension)
							set the sourceFile to (move thisItem to the tempFolder with replacing) as alias
						end tell
						processItem(sourceFile, newName, resultsFolder)
					else
						tell application "Printer Setup Utility"
							open thisItem
							repeat while (busy status of itemInfo)
								delay 1
							end repeat
							quit
						end tell
						tell application "Finder" to delete file thisItem
					end if
				end if
				
				if the name extension of the itemInfo is "tmp" then
					
					set outputAlias to tempFolder as alias
					set outFolderPosix to POSIX path of outputAlias
					
					(*
					if (the name of the itemInfo is getPtrName) then
						set thisPosixItem to quoted form of POSIX path of thisItem
						getPrinterName()
						do shell script "rm " & thisPosixItem
					end if
					*)
					
					if (the name of the itemInfo is getClipName) then
						set thisPosixItem to POSIX path of thisItem
						try
							do shell script "rm " & quoted form of thisPosixItem
						on error
							tell me to activate
							display dialog "Didn't delete GETCLIP.TMP" giving up after 20
						end try
						getClip()
					else
						if (the name of the itemInfo is sendClipName) then
							set thisPosixItem to POSIX path of thisItem
							set utfPosix to outFolderPosix & "utf.txt"
							do shell script "iconv -f 437 -t MacRoman " & quoted form of thisPosixItem & " > " & quoted form of utfPosix
							set the clipboard to (read POSIX file utfPosix)
							try
								do shell script "rm " & quoted form of thisPosixItem
								do shell script "rm " & quoted form of utfPosix
							on error
								tell me to activate
								display dialog "Didn't delete files" giving up after 20
							end try
						end if
					end if
					
				end if
			end if
			
		end repeat
	on error errorMessage number errorNumber
		if the errorNumber is not -128 then
			tell application "Finder"
				activate
				display dialog errorMessage buttons {"Cancel"} default button 1 giving up after 120
			end tell
		end if
	end try
end adding folder items to

You missed an important detail in the if then else structure.

You may code :


if variable_1 = value_1 then
	-- apply required actions
else if variable_1 = value_2 then
	-- apply required actions
else if variable_1 = value_3 then
	-- apply required actions
else if variable_1 = value_3 then
	-- apply required actions
else
	--apply required actions
end if

and of course, you may insert more than four cases.

Yvan KOENIG (VALLAURIS, France) mercredi 3 novembre 2010 19:05:55

Yvan,

That was EXACTLY the crucial detail that I didn’t know. Many thanks!