View Single Post
  #236  
Old 09-23-2019, 10:08 AM
Oliver M Oliver M is offline
Member
 
Join Date: Dec 1969
Location: Europe
Posts: 1,108
Default Re: Automation AppleScripts for Pro Tools (Mac)

echoesoflife,

here is a combination of cliclick and the key down and up commands that does what you want (it clicks the actual markers by name).
I also added some code to check whether the Memory Locations window is open and if not opens it.
This works flawlessly here.

Code:
property cliclickCLIPath : missing value
property shortDelay : 0.1
property medDelay : 0.3

set cliclickCLIPath to "usr/local/bin/cliclick"

tell application "System Events"
	tell process "Pro Tools"
		set frontmost to true
		-- Open Memory Locations window if it is not open already
		if not (exists window "Memory Locations") then
			click menu item "Memory Locations" of menu "Window" of menu bar item "Window" of menu bar 1
			repeat until exists window "Memory Locations"
				delay shortDelay
			end repeat
		end if
		
		-- Set variable for Memory Locations window
		set mlWindow to (1st window whose name contains "Memory Locations")
		delay shortDelay
		tell mlWindow
			try
				-- Click "Start" marker
				repeat with aRow in row of table "Memory Locations"
					if name of static text of UI element 2 of aRow starts with "Start" then
						tell static text "Start" of UI element 2 of aRow
							set {xPosition, yPosition} to position
							set {xSize, ySize} to size
							my cliClick("c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
						end tell
					end if
				end repeat
				
				-- Click "End" marker and extend selection
				repeat with aRow in row of table "Memory Locations"
					if name of static text of UI element 2 of aRow starts with "End" then
						tell static text "End" of UI element 2 of aRow
							set {xPosition, yPosition} to position
							set {xSize, ySize} to size
							key down {shift}
							my cliClick("c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
							key up {shift}
						end tell
					end if
				end repeat
				
			on error e number n
				tell application "Pro Tools" to display alert "An Error Occurred" message e & " (" & n & ")" buttons {"Cancel"} default button 1
			end try
		end tell
	end tell
end tell

on cliClick(process)
	do shell script quoted form of cliclickCLIPath & " -r " & process
end cliClick
I have no idea what your extra uiScript does but if the above code still fails on your machine then I suggest to have a look at that particular script.

Last edited by Oliver M; 09-24-2019 at 07:01 AM. Reason: Corrected/added a few comments.
Reply With Quote