Why isn't this while-clause true?

I have a simple function that wait for a webpage in Safari to be empty:

	repeat while document 1's source = ""
		log "source:" & document 1's source & ":"
		delay 0.5
	end repeat

Despite that this log-statement outputs:

source::

It doesn’t exit the loop.

According to https://programmingmonkeys.com/what-are-the-different-applescript-comparison-operators-for-strings = should work for string comparisons.

I have tried to hex dump the output and there is nothing hidden there.

Actually the code does wait for a webpage in Safari not to be empty.

The loop will be executed as long as source is empty

1 Like

Sorry, I was unclear and hadn’t really thought the question through.

Here is the whole context:

on finishedLoading(URLtoLoad)
	tell application "Safari"
		set URL of document 1 to "about:blank"
		repeat until document 1's source = ""
			delay 0.5
		end repeat
		set URL of document 1 to URLtoLoad
		repeat while document 1's source = ""
			log "source3:" & document 1's source & ":"
			delay 0.5
		end repeat

The issue is not the loop - it is the fact that setting the URL of the document doesn’t have any effect. As you can see, I want to be sure that the window is empty before I set the URL to a regular web page. But for some reason that line most of the time doesn’t have any effect (it does work sometimes).

why are you setting the URL to blank first, just put it to the URLToLoad

Also the script works for me