View Single Post
  #254  
Old 11-17-2019, 06:08 PM
echoesoflife echoesoflife is offline
Member
 
Join Date: Aug 2019
Location: Melbourne, Australia
Posts: 15
Default Re: Automation AppleScripts for Pro Tools (Mac)

Hi all,

Looks like I was able to make the first version of the automatic bounce script to work.

Here is the code.

I will continue debugging it and adding small improvements.

Kindly let me know if it's usable on your end. Highly appreciate all your help and attention along the way.

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

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

set theFolders to {}
repeat
	try
		set theFolders to theFolders & (choose file with prompt "Choose your PT files to bounce. Choose Cancel when finished with all folders" with multiple selections allowed)
		get theFolders
	on error
		display notification "Exiting"
		exit repeat
	end try
end repeat
get theFolders

set i to 0
set aRow to 0
set bRow to 0
set mySession to {}


repeat with i from 1 to (count of theFolders)
	set mySession to item i of theFolders
	set sessionName to name of (info for mySession) as string
	set sessionNameTrim to trimText(sessionName, ".ptx", "end")
	tell application "Finder" to open mySession using application file id "com.avid.ProTools" as alias
	
	delay shortDelay
	tell application "System Events"
		tell process "Pro Tools"
			
-- TO FINISH HERE - to click Don't Save if PT project is already open

			if exists button "Don't Save" of window 1 then
				click button "Don't Save" of window 1
			end if
			
			
			if i is not equal to 1 then
				if not (exists button "Don't Save" of window 1) then
					repeat until exists button "Don't Save" of window 1
					end repeat
				end if
				click button "Don't Save" of window 1
			end if
			
			
			
			try
				
				set frontmost to true
				
				-- Open Memory Locations window if it is not open already
				
				if not (exists window "Memory Locations") then
					repeat until exists window "Memory Locations"
						click menu item "Memory Locations" of menu "Window" of menu bar item "Window" of menu bar 1
						
						--	key code 87 using {command down}
						
						delay shortDelay
					end repeat
				end if
				
				
				-- Set variable for Memory Locations window
				set mlWindow to (1st window whose name contains "Memory Locations")
				
				-- Maximize Memory Locations window for script to be able to click on each marker
				delay shortDelay
				tell mlWindow
					delay shortDelay
					-- Maximize window
					click button 10 of mlWindow
					
					
					
					try
						
						-- click "Start"
						set aRow to row 1 of table "Memory Locations"
						tell aRow
							set {xPosition, yPosition} to position
							set {xSize, ySize} to size
							my cliClick("c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
						end tell
						
						
						
						-- click "End"				
						set b to count of row of table "Memory Locations"
						
						set bRow to row b of table "Memory Locations"
						tell bRow
							key down {shift}
							delay shortDelay
							set {xPosition, yPosition} to position
							set {xSize, ySize} to size
							
							my cliClick("c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
							key up {shift}
						end tell
						
						
						
						
						
					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
				
				-- Press ⌥⌘B
				tell application "System Events" to key code 11 using {option down, command down}
				
				-- Press "Bounce"
				
				tell application "System Events"
					tell process "Pro Tools"
						try
							-- HERE TO ADD ALL THE VARIABLES
							--	Change name of bounced file to Session Name Trim
							
							set bField to text field 1 of window 1
							tell bField
								delay shortDelay
								set {xPosition, yPosition} to position
								set {xSize, ySize} to size
								
								my cliClick("c:" & xPosition + (xSize div 10) & "," & yPosition + (ySize div 2))
								key code 0 using {command down}
								keystroke sessionNameTrim
								
							end tell
							
							
							click button "Bounce" of window 1
							
							delay shortDelay
							
							keystroke return
							
							-- Wait until bounce finishes
							
							repeat until (static text "Bouncing..." of window 1 exists)
							end repeat
							repeat until not (static text "Bouncing..." of window 1 exists)
							end repeat
							
							
							
							
						end try
						
						
						
						
						
					end tell
					
				end tell
			end try
		end tell
	end tell
	
end repeat

if i is equal to (count of theFolders) then
	tell application "System Events"
		tell process "Pro Tools"
			key code 13 using {shift down, command down}
			repeat until exists button "Don't Save" of window 1
			end repeat
			
			click button "Don't Save" of window 1
		end tell
	end tell
end if



on cliClick(process)
	do shell script quoted form of cliclickCLIPath & " -r " & process
end cliClick


on trimText(theText, theCharactersToTrim, theTrimDirection)
	set theTrimLength to length of theCharactersToTrim
	if theTrimDirection is in {"beginning", "both"} then
		repeat while theText begins with theCharactersToTrim
			try
				set theText to characters (theTrimLength + 1) thru -1 of theText as string
			on error
				-- text contains nothing but trim characters
				return ""
			end try
		end repeat
	end if
	if theTrimDirection is in {"end", "both"} then
		repeat while theText ends with theCharactersToTrim
			try
				set theText to characters 1 thru -(theTrimLength + 1) of theText as string
			on error
				-- text contains nothing but trim characters
				return ""
			end try
		end repeat
	end if
	return theText
end trimText
__________________
Pro Tools 2019, Hackintosh High Sierra
Reply With Quote