Making applescript recognize other boxes

I have a script that I have written that is intended to record an event and shut down at a specific time. My problem is that I have to ensure that the right audio interface is loaded.

When I open up the program, It will properly respond to “click” commands in that window. If my action opens up another widow, it will not respond to “click” commands in the new window.

How can I make this window active?

I apologize for my coding. This is my first attempt. I am open to all suggestions.

Thanks!

tell application "Digital Performer" to activate
tell application "System Events"
	delay 30
	click at {1204, 810} (this opens the interface window and works as intended)
	delay 5
	click at {790, 530}. (this selects the correct interface in the new window but isn't recognized)
	delay 5
	click at {980, 810}.  (this closes the window but isn't recognized)
	delay 20
	key code 31 using command down
	delay 0.5
	tell application "Finder"
		open file "Macintosh HD:Users:JBrown:Desktop:Untitled Project:Untitled.dpdoc"
		delay 45
		tell application "System Events"
			tell application process "Digital Performer"
				key code "85"
				delay 30
				key code "49"
				delay 30
				key code 13 using {command down, shift down}
				delay 10
				click at {860, 480}
				delay 2
				click at {870, 530}
				delay 10
			end tell
		end tell
	end tell
end tell
end

You have nested tell blocks, which is never a good idea. And a bare ‘end’ at the end, which should not be there.
And yes, you should first activate the application you want to control. When telling Finder to open a file it’s not certain Digital Performer is still frontmost.

I have no idea if this solves your problem, but here’s the amended code:

tell application "Digital Performer" to activate
tell application "System Events"
	delay 30
	click at {1204, 810}
	delay 5
	click at {790, 530}
	delay 5
	click at {980, 810}
	delay 20
	key code 31 using command down
	delay 0.5
end tell

tell application "Finder"
	open file "Macintosh HD:Users:JBrown:Desktop:Untitled Project:Untitled.dpdoc"
	delay 45
end tell

tell application "Digital Performer" to activate

tell application "System Events" to tell application process "Digital Performer"
	key code "85"
	delay 30
	key code "49"
	delay 30
	key code 13 using {command down, shift down}
	delay 10
	click at {860, 480}
	delay 2
	click at {870, 530}
	delay 10
end tell

Oh, and please don’t type additional text into script code in your post. It will likely screw up formatting.

AppleScript was designed to handle nested tell blocks, that’s really not an issue.

Nor does Finder make itself frontmost when a command is executed. Sending an activate command (0r setting a processes frontmost to true in SE) is a good idea if it needs to be frontmost for the script, especially if something else could have been brought to the front by another script or one of those pesky users.

When using GUI scripting, I find the “click at” commands to be the least reliable. Clicking buttons, selecting menu choices, and key codes all seem to work more reliably.

Also, this is a bit problematic:

What application would that open? It would be better if you could send that command to the application (many unscriptable applications will respond to the open command)

if that doesn’t work, you could write a routine for System Events to wait until that file’s window is open in the application process. That’s a little tricky, and we could help you with it, but it’s probably worth it to eliminate a 45 second delay.

But, for starters, try this:


tell application "System Events"
	tell application process "Digital Performer"
		set its frontmost to true
		delay 30
		click at {1204, 810} -- (this opens the interface window and works as intended)
		delay 5
		click at {790, 530} -- (this selects the correct interface in the new window but isn't recognized)
		delay 5
		click at {980, 810} --  (this closes the window but isn't recognized)
		delay 20
		key code 31 using command down
		delay 0.5
	end tell
	tell application "Finder" to open file "Macintosh HD:Users:JBrown:Desktop:Untitled Project:Untitled.dpdoc"
		delay 45
		tell application "System Events"
			tell application process "Digital Performer"
				key code "85"
				delay 30
				key code "49"
				delay 30
				key code 13 using {command down, shift down}
				delay 10
				click at {860, 480}
				delay 2
				click at {870, 530}
				delay 10
			end tell
		end tell
	end tell
  

Man, I really appreciate the help since I just started learning this stuff so PLEASE tell me when I do goofy crap!

That being said, I cleaned up the code and it does make more logic but the problem still persists.

I had read that clicks are not good, especially since this menu can move and the program remembers its LAST position. The menu itself IS accessible through the menu…but I can open THAT ONE up with a click with no issues. The menu that it opens up is only selectable with a mouse the best I can tell. But the click command does not seem to work on that window. That is why I am assuming that I have to do something to “activate” that window to make click commands recognize it. Clicks still continue to work on the first menu even if the menu it opens is on top of it.

The file referred to in the “open file” line also will open the application Digital Performer if it is closed

This was really two different scripts put together. The bottom half where it opens the file till the end works as intended. It opens a file, starts the recording process, stops it, and closes the file as I want it. Although I have never tested it beyond 30 seconds. The real time will be 1 hour and 15 min…4500 sec. Is there a smarter way to do that?

My problem starts at the point where it says to click at 790,530. It just goes silent after that.

As far as some of the delays go, this is a digital audio recording program that is tracking 54 tracks of audio every Sunday with a ton of plugins. It just takes time to finish loading. If that isn’t what you’re addressing, then help me pls.

Once again, I am thrilled so many people are trying to help. If I can make this work, I will start looking at other uses to make my life easier.

Thanks

Model: Macbook Pro M1 Max
AppleScript: 2.11
Browser: Safari 537.36
Operating System: macOS 12

Go ahead and post your updated script and we can have a look.

For me, it’s the “click at” which I find problematic. There are variables like window size that can throw that off.

If you can identify the button itself, by name or index, clicking that is usually better. If you have UI Browser, or Script Debugger, that can help you get the ID of the button. I think you’d find that more reliable.

There could be. What I was thinking is you were giving the script extra time to make sure the file had fully loaded. Seems like something else.

If it is a finishing loading issue, then the tell application X to open file might help. Otherwise, you can experiment with system events.

Ok, Here is the updated script. The click numbers are different to account for testing on my laptop. Is it possible to post an image to show my desktop here?

tell application "Digital Performer" to activate
delay 20
tell application "System Events" to tell application process "Digital Performer"
	click at {1203, 808}
	delay 6
	click at {228, 537}
	delay 5
	click at {420, 815}
	delay 10
end tell

tell application "Finder"
	open file "Macintosh HD:Users:JBrown:Desktop:Untitled Project:Untitled.dpdoc"
	delay 20
end tell
tell application "Digital Performer" to activate
tell application "System Events"
	tell application process "Digital Performer"
		key code "85"
		delay 30
		key code "49"
		delay 30
		key code 13 using {command down, shift down}
		delay 10
		click at {860, 480}
		delay 2
		click at {870, 530}
		delay 10
		
	end tell
end tell

end

Not familiar with that at all. Is that something that works with/inside the applescript? If so, how would you use it?

Thanks

ok, explain this to me like I am a musician…not a programer…(this is true)

With this line:

do shell script “/opt/homebrew/bin/cliclick c:20,20”

If I were to use this in applescript, how would I write it? What is the function of “/opt/homebrew/bin” section?

I get the cliclick c:20,20 is the command to click at location 20,20 correct?

Sorry to be slow…I just thought that writing a script to click on a box on a window would have been so much easier. The first box is easy, it’s the second box that is causing me fits.

Help me figure out the command pls