Error Message: The specified object is a property, not an element

The script below was working last December but when I ran the script today it said:
“The specified object is a property, not an element.”
???

set myWindow to makeMyWindow()
tell application "Safari" 	
	set the URL of document 1 of myWindow to ("https://www.apple.com")	
end tell
on makeMyWindow()
	set aName to ((random number from 10000000 to 99999999 as integer) as text)
	tell application "Safari"
		make new document with properties {name:aName}
		set everyWindow to every window
		repeat with eachWindow in everyWindow
			tell eachWindow
				set everyDocument to every document
				repeat with eachDocument in everyDocument
					tell eachDocument
						if name is aName then
							return eachWindow
						end if
					end tell
				end repeat
			end tell
		end repeat
	end tell
end makeMyWindow

I changed
set the URL of document 1 of myWindow to ("https://www.apple.com")
to
set the URL of tab 1 of myWindow to ("https://www.apple.com")
and it is ‘working’.

Hi.

Yeah. In Safari, a document’s either an element of Safari itself or a property of a window, equivalent to the current tab. So any of these …

tell application "Safari"
	-- Specifically the window's first tab.
	set the URL of tab 1 of myWindow to ("https://www.apple.com")
	-- The window's currently showing tab/document.
	set the URL of current tab of myWindow to ("https://www.apple.com")
	-- Ditto.
	set the URL of document of myWindow to ("https://www.apple.com")
	-- Safari's front document — ie. the currently showing document of its front window.
	set the URL of document 1 to ("https://www.apple.com")
end tell

… but not what you tried originally.

My problem was that I had ran this script section all of last year and years before in several scripts without the error message. Then yesterday I ran the script and it generated an error message.

Does a window in Safari have only a single document and one doesn’t have to say which document index? Is this new?

As far as Safari’s AppleScript terminology’s concerned, yes. A Safari window has a ‘document’ property whose value is the document currently showing in that window. Safari itself contains things called ‘documents’ which are all the documents currently showing in any of the windows. Safari windows contain things called ‘tabs’ which are all the documents in those windows, showing or not. :-}

Well…. Yes and no, possibly. In the dictionary of Safari 5.0.6 on my old G5, there’s nothing linking documents with windows at all. But with two tabs in the front window, the following all return a single string which is the URL of the current tab:

tell application "Safari"
	URL of document of window 1
	URL of document 1 of window 1
	URL of documents of window 1
end tell

However, this produces the “object is property not element” error:

tell application "Safari"
	URL of document 2 of window 1
end tell

So at least as long ago as 2011, Safari windows may have had ‘document’ properties, Safari’s dictionary didn’t mention this, and certain element specifiers worked when they shouldn’t have! I don’t know when this was tightened up, but I can believe your script used to work.

Hello,

I now tried to export a movie in QuickTime Player 7 and got exactly the same message. There’s only the class document, not movie. I’m puzzled. My script is very simple.

property MovieTitle : ""
property Ext : {".mov", ".mp4", ".aif", ".aiff", ".mp3", ".m4a", ".avi", ".wav", ".wave", ".wv"}
property ExportPath : POSIX path of (path to movies folder)


tell application "QuickTime Player 7"
tell document 1
	set MovieTitle to name
	set AppleScript's text item delimiters to Ext
	set MovieBaseName to text item 1 of MovieTitle
	
	set DocumentPath to (POSIX file (ExportPath & MovieBaseName & ".mp4")) of me
	
	export to DocumentPath as MPEG4 using settings preset "Movie to MPEG-4" with replacing
	
end tell

end tell

Every time I add the optional parameter using settings preset it chokes with this error. I tried to direct this command to the top-level app object, to the video-track to no avail. I don’t understand what “specified object” is the offender?