View Single Post
  #218  
Old 09-09-2019, 05:38 AM
Oliver M Oliver M is offline
Member
 
Join Date: Dec 1969
Location: Europe
Posts: 1,008
Default Re: Automation AppleScripts for Pro Tools (Mac)

Quote:
Originally Posted by henningaround View Post
Yeah, you're right. That's were one can see that I don't write the code myself but copy and paste stuff together and modify it until it works
There's nothing wrong with that. 😉

Here's a cleaned up version with error checking.

Code:
if ptIsRunning() then
	-- Define Insert to open here
	set Insert_to_open to "Insert Assignment A"
	
	tell application "System Events"
		tell process "Pro Tools"
			set frontmost to true
			-- Define the correct Insert group
			if (Insert_to_open = "Insert Assignment A") then
				set Insert_group to "Inserts A-E"
			end if
			
			tell (1st window whose title contains "Edit: ")
				try
					set selectedTrack to title of button of UI element 2 of (1st row of table "Track List" whose selected is true)
					set formattedString to text of selectedTrack as string
					set AppleScript's text item delimiters to "Selected. "
					set theTextItems to every text item of formattedString
					set AppleScript's text item delimiters to ""
					set formattedString to theTextItems as string
					
				on error e number n
					if the n is -1719 then
						tell application "Pro Tools" to display alert "No track was selected." message " " buttons {"Cancel"} default button 1
						return
					else
						tell application "Pro Tools" to display alert "An Error Occurred" message e & " (" & n & ")" buttons {"Cancel"} default button 1
					end if
				end try
				
				if exists (button Insert_to_open of group Insert_group of group formattedString) then
					click button Insert_to_open of group Insert_group of group formattedString
				else
					return
				end if
			end tell
		end tell
	end tell
end if

on ptIsRunning()
	return application "Pro Tools" is running
end ptIsRunning
Reply With Quote