Using a text file as part of the variable input

So I’m trying to write a script/folder action that’ll watch a folder until x amount of files drop in, then it’ll run the next part (PDF files dropping in, then when x amount of PDFs are made, make in to 1 PDF, where x is defined from another script processing docs)

So far, the script works if I replace ‘PDFCount’ with an actual number. I just can’t get it to read the text file as the input number, instead of a number I enter. The dialogs are just until I can get a result I want, so that’ll change later when it progresses past this hurdle. Inside the text file is just simply a digit, so 4 for example, nothing else.

set fileCount to read file ("Megatron:Users:kit:Desktop:File count.txt")
set PDFCount to "" & fileCount & ""

tell application "Finder"
	
	repeat count (folder "4")'s files times
		count files of entire contents of (folder "4")
		if the result = PDFCount then
			display dialog "And it's off!"
		else
			delay 3
			display dialog "counting down"
			
		end if
	end repeat
end tell

For fyi, the script that makes the text file is (after this part is done, it continues on to move files one by one from one folder to another until the folder is empty);

tell application "Finder"
	
	set the FileNumber to (number of files in folder "1")
	set FileText to "" & FileNumber & ""
	
	tell application "TextEdit"
		make new document
		
		set the text of the front document to FileText
		save document "Untitled" in file "Megatron:Users:kit:Desktop:File count.txt"
		quit saving no
	end tell
end tell

Hi,

One thing, change:
set PDFCount to “” & fileCount & “”
to:
set PDFCount to fileCount as integer

In your file-writing script you have nested tell blocks, which is not a good idea.

Furthermore, there’s no need to involve TextEdit at all; AppleScript can do this on its own:

tell application "Finder" to set FileNumber to number of files in folder "1"
set myFile to "Megatron:Users:kit:Desktop:File count.txt"

set fref to open for access file myFile with write permission
write FileNumber to fref as text
close access fref

Ahhhhh that’s the word I think I was looking for! Does it even need the second line tho? Can’t it just be told that the fileCount is the integer?
Thanks!

Yeah, still learning. I figured that nested Tell blocks aren’t good, but not sure how to get around that part just yet. Working on it tho!
Thanks for tweaking!