Is a subroutine the best option here?

Very little experience with scripting but I’m actually enjoying learning this stuff!

I want a subroutine (I think?) in my script to check a certain value. If the value is 2 or greater, then the script can proceed. If the value is less than 2 then a web page needs to be clicked once and then the script can proceed.

I tried going down the IF/ELSE route but I couldn’t get the script to proceed after the webpage had been clicked.

Therefore I tried the code below but it doesn’t ever click the page.

Any help greatly appreciated!

tell application “Finder”
set attchList1 to every file of alias “Path:To:Folder:”
set theCNT1 to count of attchList1
end tell

on download_check()

if theCNT < 2 then
	
	activate application "Safari"
	tell application "System Events"
		tell process "Safari"
			click at {609, 464}
		end tell
	end tell
	
	
	
end if

end download_check

Welcom to MacScripter! :slight_smile:

Try, and compare this, and you’ll figure it out! :slight_smile:


tell application "Finder"
	set attchList1 to every file of alias "Path:To:Folder:"
	set theCNT1 to (count attchList1)
end tell

download_check(theCNT1)

on download_check(tc)
	
	if tc < 2 then
		activate application "Safari"
		tell application "System Events"
			tell application process id "com.apple.safari"
				click at {609, 464}
			end tell
		end tell
	end if
end download_check


Thanks McUsr!

That was really helpful. I have managed to remove a lot waffle from my code knowing this. Cheers