Having trouble finding correct menu item

I have the following little script I’m just starting:

set the destination_file to "/Users/jeffrey/Downloads/jotts/mp3s/4836-befb-339676e874c6.mp3"
activate application "FileMaker Pro Advanced"
tell application "System Events"
	tell process "FileMaker Pro Advanced"
		click menu item "QuickTime." of menu 4 of menu bar item "Insert" of menu bar 1
	end tell
end tell

The 4th menu is called Insert (if I’m counting right :slight_smile: ), and the Menu Item is called “QuickTime…” But I get this error:

error “System Events got an error: Can’t get menu 4 of menu bar item "Insert" of menu bar 1 of process "FileMaker Pro Advanced". Invalid index.” number -1719 from menu 4 of menu bar item “Insert” of menu bar 1 of process “FileMaker Pro Advanced”

I’ve also tried this as menu 3 and 5, just in case, and still get the same error.

Well, I found my error. Of course, menu 4 should be menu 1, as it’s in the first menu of the Insert menu.

So with that, I’ve gotten a bit farther. I now have the following script:

set the destination_file to "/Users/jeffrey/Downloads/jotts/mp3s/somebunchofnu mbers.mp3"
activate application "FileMaker Pro Advanced"
delay 0.2
tell application "System Events"
tell process "FileMaker Pro Advanced"
click menu item "QuickTime." of menu 1 of menu bar item "Insert" of menu bar 1
delay 0.2
tell window 1
keystroke "g" using {command down, shift down}
repeat until exists sheet 1
delay 0.2
end repeat
end tell
tell sheet 1
set value of text field 1 to destination_file
click button "Go"
end tell
end tell
end tell

This opens the open/save for Insert–>QuickTime…, then opens the standard OS Go To Folder sheet. Then I get:

error “System Events got an error: Can’t get sheet 1 of process "FileMaker Pro Advanced". Invalid index.” number -1719 from sheet 1 of process “FileMaker Pro Advanced”

Can someone tell me what I’m doing wrong?

And farther. I now have a script which works in as itself perfectly, but when run in FMP, it keeps beeping and not performing.

I diagnosed this to one error: delay. Anytime I put a delay of any kind in the script, it never opens the Insert QuickTime… window, and so balks at everything after. If there are no delay’s, it runs smoothly, unfortunately, so fast, that by the time it gets to the end, all it can do is beep.

Can someone tell me what’s going on here?

Here’s the script – without the delays.

tell application "System Events"
tell process "FileMaker Pro Advanced"
click menu item "QuickTime." of menu 1 of menu bar item "Insert" of menu bar 1
tell window 1
keystroke "g" using {command down, shift down} //this should open Go To Folder
keystroke "v" using {command down} //this pastes the path, which has been checked and is POSIX correct. We're getting here OK.
end tell
tell window 1
key code 36 //this clicks Enter. By the time it gets here, it just beeps twice and does nothing further, indicating it can't click Enter, Enter
end tell
tell window 1
key code 36 //this clicks Enter
end tell
end tell
end tell