applescript for pro tools problem

HI everybody

FIRST
A big thank you for all the contributions…
Really nice…

i 'm in the begin of my apllescript adventure.
and thank of you i understand more and more.

BUT

i try to make a script in Pro tools app for select the menu by criteria in soundfiled recording.
it’s ok
BUT

the end of the script is very very slow juste to do 3 key code action…
i don’t understand.
maybe you can help me.
here is the script

activate application "Pro Tools"
tell application "System Events"
    tell application process "Pro Tools"
        
        set window_name to name of front window
        -- key code for copy paste
        key code 8 using {command down}
        key code 41
        key code 9 using {command down}
        -- click pop up button for track P1
        click pop up button 1 of group "P1 - Audio Track " of window window_name
        -- type e for select expand channels and by criteria
        
        -- PROBLEM THE SRCIPT  VERY VERY LONG TIME TO DO THE NEXT STEP
        
        key code 14
        key code 124
        key code 36
    end tell
    
    
    
end tell

Thanks in advance.
best

ps : sorry for my beautifull PERFECT english

I don’t know what all these keycodes do, but I think it’s better to take them out of the blocks tell process “Pro Tools” and send them directly to “System Events”:


activate application "Pro Tools"

tell application "System Events"
	
	tell application process "Pro Tools" to set window_name to name of front window
	-- key code for copy paste
	keystroke "c" using command down -- Copy of Edit menu
	key code 41 -- ";" -- what this does???
	keystroke "v" using command down -- Paste of Edit menu
	
	tell application process "Pro Tools"
		-- click pop up button for track P1
		click pop up button 1 of group "P1 - Audio Track " of window window_name
		-- type e for select expand channels and by criteria
	end tell
	
	keystroke "e"   --- ????
	key code 124 -- Right Arrow ---???
	keystroke return ----????
	
end tell

NOTE: I guess, you want use something like this shortcut, but I don’t know what it does:

keystroke "e" & return using right

or, as this:


keystroke "e" using right
keystroke return

Hello
thank you for the answer.
i was not really understandable…sorry.
by the way Oliver M solve the problem in another forum.
it’s a problem with pro tools and right click .
and the issue was Cliclick.
here the new script

property cliclickCLIPath : missing value

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

activate application "Pro Tools"
tell application "System Events"
	tell application process "Pro Tools"
		
		set window_name to name of front window
		-- key code for copy paste
		keystroke "c" using command down
		keystroke "m"
		keystroke "v" using command down

		-- click pop up button for track P1 
		tell pop up button 1 of group "temoin - Audio Track " of window window_name		
			set {xPosition, yPosition} to position
			set {xSize, ySize} to size
			my cliClick("rc:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
			
			
		--to make selection in the rght click
			key code 14 -- selection letter E in the righ click for go to good selection
			key code 124 --right arrow to go to next step in right selection
			key code 36 -- enter
			
			
		end tell
	end tell
	
	
	
end tell

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

thank you again for your help.

a rapid question…

what 's the diference in use keystroke “c” and key code 8 ???

now i will try to "organize " my little script to be more efficient
i find that the beginnnig if very slow…

best
jf

They does the same job, but for the keys which has letter-representation, keystrokes is more human readable. For example, it is easy to keystroke “my dog” in some textfield and you see in the code what it does too. Special symbols you can’t keystroke, so can’t avoid using key code.

Some special symbols however has its AppleScript representations (once again, to be human readable), as AppleScript constants.
This:


key code 14 -- selection letter E in the righ click for go to good selection
key code 124 --right arrow to go to next step in right selection
key code 36 -- enter

is equivalent to this:


keystroke "e"
keystroke right
keystroke return

yes i have good understand …
but i was just to be sur…

thank you

i’ll be back for another questionS for sur.
best
jf

As I say above the keystrokes and key codes is the job for System Events and not for process. The process window only should be the frontmost. I have not “Pro Tools” on my Mac, but it is interesting for me if the following script works correct:


tell application "Pro Tools" to activate

tell application "System Events"
	-- key code for copy paste
	keystroke "c" using command down
	keystroke "m"
	keystroke "v" using command down
	tell application process "Pro Tools" to tell front window
		-- click pop up button for track P1 
		tell pop up button 1 of group "temoin - Audio Track "
			set {{xPosition, yPosition}, {xSize, ySize}} to {position, size}
		end tell
	end tell
end tell

my cliClick("rc:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))

tell application "System Events"
	--to make selection in the rght click
	key code 14 -- selection letter E in the righ click for go to good selection
	key code 124 --right arrow to go to next step in right selection
	key code 36 -- enter
end tell


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

no the script don’t work

error
the variable cliclickCLIPath is not defined

it works with

property cliclickCLIPath : missing value

set cliclickCLIPath to “usr/local/bin/cliclick”

property cliclickCLIPath : missing value

set cliclickCLIPath to "usr/local/bin/cliclick"
tell application "Pro Tools" to activate

tell application "System Events"
	-- key code for copy paste
	keystroke "c" using command down
	keystroke "m"
	keystroke "v" using command down
	tell application process "Pro Tools" to tell front window
		-- click pop up button for track P1 
		tell pop up button 1 of group "temoin - Audio Track "
			set {{xPosition, yPosition}, {xSize, ySize}} to {position, size}
		end tell
	end tell
end tell

my cliClick("rc:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))

tell application "System Events"
	--to make selection in the rght click
	key code 14 -- selection letter E in the righ click for go to good selection
	key code 124 --right arrow to go to next step in right selection
	key code 36 -- enter
end tell


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

I forgot to replace cliclickCLIPath with “usr/local/bin/cliclick”. No need property and variable:

do shell script (quoted form of "usr/local/bin/cliclick") & " -r " & coordinate

The main thing, however, is that, as I expected, the keystrokes and key codes work just that way - outside of processes.

ok
i try to do a click with option with clciclick for another action.
but it 's don’t work
i write
my cliClick(“kd:alt” & xPosition + (xSize div 2) & “,” & yPosition + (ySize div 2))

??

best
jf

My understanding is that a space character was missing.
May you try :

my cliClick("kd:alt " & xPosition + (xSize div 2) & “,” & yPosition + (ySize div 2))

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 11 décembre 2019 19:10:38

hello
thank you for help but don’t work
Unrecognized action shortcut “52,172”
i think there is another probelm in my script.
right click work but not this.
i will find :slight_smile:

Why do you believe,that it doesn’t work? This action is only pressing key “option” DOWN. But to do whole click action you should after some delay release the key sending event KEY UP:


my cliClick("kd:alt" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
delay 0.1
my cliClick("ku:alt" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)) 

@KniazidisR

Here,
my cliClick(“kd:alt” & xPosition + (xSize div 2) & “,” & yPosition + (ySize div 2))
issue :
error "Invalid key “alt60” given as argument to command “kd”.
The key name may only be one of:

  • alt
  • cmd
  • ctrl
  • fn
  • shift" number 1

my cliClick("kd:alt " & xPosition + (xSize div 2) & “,” & yPosition + (ySize div 2))
issue :
error “Unrecognized action shortcut “60,50”” number 1

my cliClick("kd:alt " & xPosition + (xSize div 2) & ", " & yPosition + (ySize div 2))
issue :
error “Unrecognized action shortcut “60,”” number 1

I will search to see if my cliclick file is up to date.

Edit. My version is “cliclick 4.0.1, 2018-04-10”, it’s up to date.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 14 décembre 2019 13:56:36

I read the CliClick usage guide and see that my script above is wrong. Most likely this is correct syntax:


my cliClick("kd:alt")
my cliClick("c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2))
my cliClick("ku:alt")

I have not Pro Tools to test.

I tested - it works fine. The following opens Extended Menu of my WiFi:


my cliClick("kd:alt")
my cliClick("c:844,10")
my cliClick("ku:alt")

on cliClick(coordinate)
	do shell script "usr/local/bin/cliclick " & coordinate
end cliClick

@KniazidisR

What with :

my cliClick("kd:alt  c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)) & " ku:alt"

# Your modified handler (without (" -r ")
on cliClick(coordinate)
	do shell script quoted form of cliclickCLIPath & " " & coordinate
end cliClick

and with :

my cliClick("kd:alt  c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)) & " ku:alt"

# The original handler (with (" -r ")
on cliClick(coordinate)
	do shell script quoted form of cliclickCLIPath & " -r " & coordinate
end cliClick

Here both behave flawlessly but I don’t know if they do their wanted duty.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 14 décembre 2019 15:30:18

hello
thank you for help.
the last version of Yvan looks work…thx

my cliClick("kd:alt c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)) & " ku:alt"

# The original handler (with (" -r ")
on cliClick(coordinate)
   do shell script quoted form of cliclickCLIPath & " -r " & coordinate
end cliClick