Jump to content

Change Region Gain With Key Commands


speakerfood

Recommended Posts

  • 1 month later...

Hi guys..

 

So far I learned quite a lot from those scripts (thnx speakerfood & scripters..) ..with help of Accessibility Inspector.

I am trying to figure out how to use decimal values.

I can change values (gain - row 9) with 'increment' and 'decrement' actions, but it moves by 10 (or 1.0)

Moving by 1 (or 0.1) would be appropriate.

 

with this code, the value moves by 0.1, but I think there is a lot more lag:

tell row 9 of outline 1 of scroll area 1 of group sub_group_nr of list 1 of group group_nr of window tracks_window

set x to (get value of slider 1)

set value of slider 1 to (x + 1)

 

Maybe someone can help me with the solution for 'increment' and 'decrement' actions to move by 0.1?

 

the script:

tell application "Logic Pro X"

tell application "System Events"

tell process "Logic Pro X"

set tracks_window to title of first window whose title contains "- Tracks"

if (description of group 1 of window tracks_window = "Control Bar") then

set group_nr to 2

else

set group_nr to 1

end if

if (value of static text 1 of group 1 of list 1 of group group_nr of window tracks_window is "Movie") then

set sub_group_nr to 2

else

set sub_group_nr to 1

end if

 

tell slider 1 of row 9 of outline 1 of scroll area 1 of group sub_group_nr of list 1 of group group_nr of window tracks_window

 

-- increment

decrement

 

end tell

end tell

end tell

end tell

 

 

 

BTW, I am using Keyboard Maestro.

 

Thnx,

Roger

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
You can use this script. Modify it to go to an exact type, by changing the keycode 125 to match the first letter of the type. If you only use this script, you also need a script to go up in the menu (key code 126 is arrow up.

 

BTW, this script is an improvement to previous scripts, because it also works when a movie is present or when Control Bar is not shown.

 

tell application "Logic Pro X"

tell application "System Events"

tell process "Logic Pro X"

set tracks_window to title of first window whose title contains "- Tracks"

if (description of group 1 of window tracks_window = "Control Bar") then

set group_nr to 2

else

set group_nr to 1

end if

if (value of static text 1 of group 1 of list 1 of group group_nr of window tracks_window is "Movie") then

set sub_group_nr to 2

else

set sub_group_nr to 1

end if

tell pop up button 1 of row 14 of outline 1 of scroll area 1 of group sub_group_nr of list 1 of group group_nr of window tracks_window

click

delay 0.2

key code 125

key code 36

end tell

end tell

end tell

end tell

 

My apologies for the typo. I meant the Fade Out Type in the Inspector window. There are 4 values: Out, X, EqP, and X S.

 

The below AppleScript was posted earlier to change the Region Gain (and works perfectly). Can this be modified to change the Fader Out Type?

 

Thanks for the help!

 

tell application "System Events"

tell process "Logic Pro X"

tell row 8 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of (first window whose name contains "- Tracks")

set x to (get value of slider 1)

set value of slider 1 to (x + 30)

end tell

end tell

end tell

 

I've upgraded to LPX 10.4.6 and the key commands no longer work. Do I need to update the scripts in BetterTouchTool?

 

Thanks!

Link to comment
Share on other sites

WRT .1 gain adjustments...

If you click on the Gain field in the region inspector you can use the key commands "-" and "=" to change the gain down or up by .1 dB - If you want to change by 1 dB increments use shift-minus and shift-equal

 

In fields like ticks the changes are 1 and 10, etc.

 

This seems to work in lots of places where you would click on the value and use the mouse to raise/lower - basically "faders" .

Link to comment
Share on other sites

thanks a lot for sharing this script! this is a great time saver!

 

just wanted to share that with my version of Logic Pro 10.4.6 and macOS 10.14.5, the correct row number for region gain is 9 and not 8, nor 6.

so here is the updated script that works for me:

 

tell application "Logic Pro X"

tell application "System Events"

tell process "Logic Pro X"

set tracks_window to title of first window whose title contains "- Tracks"

if (description of group 1 of window tracks_window = "Control Bar") then

set group_nr to 2

else

set group_nr to 1

 

end if

tell row 9 of outline 1 of scroll area 1 of group 1 of list 1 of group group_nr of window tracks_window

set x to (get value of slider 1)

set value of slider 1 to (x - 10)

end tell

end tell

end tell

end tell

Link to comment
Share on other sites

just wanted to share that with my version of Logic Pro 10.4.6 and macOS 10.14.5, the correct row number for region gain is 9 and not 8, nor 6.

so here is the updated script that works for me

 

Thanks so much for this updated script, my custom macro to change region gain is now working again! :D

Link to comment
Share on other sites

Hello,

 

Here's the script I've been using written by speakerfood to change Region Fade Out Type using BetterTouchTool. But since I upgraded to LPX 10.4.6 it doesn't work. Might anyone know how to modify the script so it works again?

 

tell application "Logic Pro X 10.4.6"

tell application "System Events"

tell process "Logic Pro X"

set tracks_window to title of first window whose title contains "- Tracks"

if (description of group 1 of window tracks_window = "Control Bar") then

set group_nr to 2

else

set group_nr to 1

end if

if (value of static text 1 of group 1 of list 1 of group group_nr of window tracks_window is "Movie") then

set sub_group_nr to 2

else

set sub_group_nr to 1

end if

tell pop up button 1 of row 15 of outline 1 of scroll area 1 of group sub_group_nr of list 1 of group group_nr of window tracks_window

click

delay 0.2

key code 125

key code 36

end tell

end tell

end tell

end tell

 

Thanks so much for any help!

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 4 weeks later...
I updated the script, it checks which version of Logic Pro X you are using so it works both in 10.4.6 and earlier versions. Also, I put the Applscript in one action that is called with the variable gainChange, so now it's easier to debug and maintain.

 

Logic Pro Change Gain.kmmacros.zip

Thank you

Link to comment
Share on other sites

  • 11 months later...

Hello,

I'm very interested in making this applescript work and triggering it with Bettertouchtool.

I would love to assign it to a trackpad gesture (for example : ctrl+scroll up = raise region gain).

 

But I have a problem when I try and run the script :

Error in system events : impossible to obtain window 1 of process "Logic Pro X" whose title contains "- Tracks". Index non valable. number -1719

 

I'm wondering if it might come from the fact that I'm running logic pro in french ?

This my first time working with an applescript so I'm a bit lost.

I'm running logic pro 10.5.1

 

Thanks for your help !

Link to comment
Share on other sites

  • 2 weeks later...

Sadly this script no longer works in Logic 10.6. Its works with the number 8 in the row but it stops working if I import a video into the project. I've tried changing the number to 10, 12, 14, 16, 18, 20... Does anyone know how to get this working again?

 

EDIT: Got it working again by reverting to an older version of the script :)

Link to comment
Share on other sites

  • 2 months later...

awesome!!!!!! works straight away! just gained down a bunch of esses faster than ever!

 

i prefer this line-based macro approach to the "found image" one. i have a macro that applies fades/crossfades to selected regions and it generally works, but if something's iffy with your screenset, it might do something odd instead. just got a stream deck, so newly enthused about macros!

Link to comment
Share on other sites

  • 7 months later...

Hey Speakerfood, did you ever work out if you can automate using AXIdentifiers? I've managed to write a few scripts for launching plugins and instruments from the Touch Bar and one for automated track colouring, group and buss assignment, all done with System Events in AppleScript and executed with a single click. But its scripted using the UIElement properties and XY locations. Im a complete novice with AppleScript but eager to find a way to automate the UI and would be really grateful for any tips :)

 

Cheers[

 

 

With a little reverse engineering I managed to create an AppleScript that changes the gain/velocity of a selected region.

You can call this script with an application like yKey, and have it mapped to any shortcut you like.

http://plumamazing.com/mac/ykey/

 

Note: this only works if you have the Control Bar visible at the top, and the Region inspector is open.

 

Applescript to change the gain +3dB or the velocity of a MIDI region by 30:

 

tell  application "System Events"

tell  process "Logic Pro X"

tell  row 6 of  outline 1 of  scroll area 1 of  group 1 of  list 1 of  group 2 of (first  window  whose  name contains "- Tracks")

set  x to (get  value of  slider 1)

set  value of  slider 1 to  (x + 30)

end  tell

end  tell

end  tell

 

Applescript to change the gain -3dB or the velocity of a MIDI region by -30:

 

tell  application "System Events"

tell  process "Logic Pro X"

tell  row 6 of  outline 1 of  scroll area 1 of  group 1 of  list 1 of  group 2 of  (first  window  whose  name contains  "- Tracks")

set  x to  (get  value of  slider 1)

set  value of  slider 1 to  (x + 30)

end  tell

end  tell

end  tell

Link to comment
Share on other sites

Actually, that's the only way you can do it, by trying to find UI Elements by their properties. But not all elements have all the properties defined, so you just have to figure out what the fastest way is to get at the UI Element you want. I would suggest diving into AppleScript, as it lets you do stuff like "give me the first element that has a property with the value X in this list". Also, try to understand and use the "try" statement, I use it a lot so that you can return gracefully from a script instead of throwing an error, and you can test several situations after each other.

 

I use UI Browser to inspect the user interface elements of applications. Crashes a lot, and can't handle some windows (like the floating Region window), but it still helps a lot.

 

Hey Speakerfood, did you ever work out if you can automate using AXIdentifiers? I've managed to write a few scripts for launching plugins and instruments from the Touch Bar and one for automated track colouring, group and buss assignment, all done with System Events in AppleScript and executed with a single click. But its scripted using the UIElement properties and XY locations. Im a complete novice with AppleScript but eager to find a way to automate the UI and would be really grateful for any tips :)

 

Cheers[

 

 

With a little reverse engineering I managed to create an AppleScript that changes the gain/velocity of a selected region.

You can call this script with an application like yKey, and have it mapped to any shortcut you like.

http://plumamazing.com/mac/ykey/

 

Note: this only works if you have the Control Bar visible at the top, and the Region inspector is open.

 

Applescript to change the gain +3dB or the velocity of a MIDI region by 30:

 

tell  application "System Events"

tell  process "Logic Pro X"

tell  row 6 of  outline 1 of  scroll area 1 of  group 1 of  list 1 of  group 2 of (first  window  whose  name contains "- Tracks")

set  x to (get  value of  slider 1)

set  value of  slider 1 to  (x + 30)

end  tell

end  tell

end  tell

 

Applescript to change the gain -3dB or the velocity of a MIDI region by -30:

 

tell  application "System Events"

tell  process "Logic Pro X"

tell  row 6 of  outline 1 of  scroll area 1 of  group 1 of  list 1 of  group 2 of  (first  window  whose  name contains  "- Tracks")

set  x to  (get  value of  slider 1)

set  value of  slider 1 to  (x + 30)

end  tell

end  tell

end  tell

Link to comment
Share on other sites

Hi Speakerfood,

 

Thanks for your reply, yeah I've been using the try statement a bit, ill look into it some more. Here's an AppleScript I'm using for UI Element inspection, it goes through all the classes, descriptions (if any) etc. You hover the mouse over an area then run the script by pressing command r. If you're having issues with your UI inspector it might be worth giving it a shot. Just compile it intro a script in script editor

 

 

 

#!/usr/bin/osascript

--------------------------------------------------------------------------------

# pnam: GET MOUSE POSITION | IDENTIFY UI ELEMENT

# nmxt: .applescript

# pDSC: Identifies the UI element reference located under the mouse cursor

 

# plst: -/Users/dh/AppleScriptive/scripts/Get Mouse Position | Identify UI Element.applescript

 

# rslt: «text» : A script containing a reference to the UI element's properties

# - : Element not accessible

--------------------------------------------------------------------------------

# sown: CK

# ascd: 2018-09-02

# asmo: 2019-06-09

--------------------------------------------------------------------------------

use application "System Events"

use scripting additions

--------------------------------------------------------------------------------

# IMPLEMENTATION:

set s to __string__({UIElement:it ¬

, UIProperties:properties ¬

, UIAttributes:name of attributes ¬

, UIActions:name of actions} of ¬

(click at my mouseLocation()))

 

-- Text manipulation --

set [a, b, c] to [length of "{UIElement:", ¬

offset of "of application \"System Events\", " in s, ¬

length of "of application \"System Events\", "]

set UIElement to text (1 + a) thru (b - 2) of s

set UIRecord to ["{", text (b + c) thru -1 of s]

 

-- Composite string --

set UIString to the contents of [¬

"use application \"System Events\"", ¬

linefeed, linefeed, UIElement, ¬

linefeed, linefeed, UIRecord] as text

 

 

set the clipboard to the UIString

return the UIString

--------------------------------------------------------------------------------

# HANDLERS:

# __string__()

# Returns a string representation of an AppleScript object

to __string__(object)

local object

 

if the object's class = text then return the object

 

try

set s to object as missing value

on error E --> "Can’t make %object% into type missing value."

set tid to the text item delimiters

set the text item delimiters to "Can’t make "

set s to text items 2 thru -1 of E as text

 

set the text item delimiters to " into type missing value."

set s to text items 1 thru -2 of s as text

 

set the text item delimiters to tid

end try

 

return s

end __string__

 

# mouseLocation()

# Gets the current cursor position relative to the top-left corner of the

# screen

on mouseLocation()

script

use framework "Foundation"

use framework "AppKit"

 

property this : a reference to current application

property parent : this

 

property NSEvent : a reference to NSEvent of this

property NSScreen : a reference to NSScreen of this

 

on mouseLocation()

set [list, [number, height]] to ¬

NSScreen's ¬

mainScreen()'s ¬

frame()

 

tell NSEvent's mouseLocation() to ¬

{its x, height - (its y)}

end mouseLocation

end script

 

result's mouseLocation()

end mouseLocation

---------------------------------------------------------------------------❮END❯

Link to comment
Share on other sites

Hi Speakerfood,

 

Thanks for your reply, yeah I've been using the try statement a bit, ill look into it some more. Here's an AppleScript I'm using for UI Element inspection, it goes through all the classes, descriptions (if any) etc. You hover the mouse over an area then run the script by pressing command r. If you're having issues with your UI inspector it might be worth giving it a shot. Just compile it intro a script in script editor

 

 

 

#!/usr/bin/osascript

--------------------------------------------------------------------------------

# pnam: GET MOUSE POSITION | IDENTIFY UI ELEMENT

# nmxt: .applescript

# pDSC: Identifies the UI element reference located under the mouse cursor

 

# plst: -/Users/dh/AppleScriptive/scripts/Get Mouse Position | Identify UI Element.applescript

 

# rslt: «text» : A script containing a reference to the UI element's properties

# - : Element not accessible

--------------------------------------------------------------------------------

# sown: CK

# ascd: 2018-09-02

# asmo: 2019-06-09

--------------------------------------------------------------------------------

use application "System Events"

use scripting additions

--------------------------------------------------------------------------------

# IMPLEMENTATION:

set s to __string__({UIElement:it ¬

, UIProperties:properties ¬

, UIAttributes:name of attributes ¬

, UIActions:name of actions} of ¬

(click at my mouseLocation()))

 

-- Text manipulation --

set [a, b, c] to [length of "{UIElement:", ¬

offset of "of application \"System Events\", " in s, ¬

length of "of application \"System Events\", "]

set UIElement to text (1 + a) thru (b - 2) of s

set UIRecord to ["{", text (b + c) thru -1 of s]

 

-- Composite string --

set UIString to the contents of [¬

"use application \"System Events\"", ¬

linefeed, linefeed, UIElement, ¬

linefeed, linefeed, UIRecord] as text

 

 

set the clipboard to the UIString

return the UIString

--------------------------------------------------------------------------------

# HANDLERS:

# __string__()

# Returns a string representation of an AppleScript object

to __string__(object)

local object

 

if the object's class = text then return the object

 

try

set s to object as missing value

on error E --> "Can’t make %object% into type missing value."

set tid to the text item delimiters

set the text item delimiters to "Can’t make "

set s to text items 2 thru -1 of E as text

 

set the text item delimiters to " into type missing value."

set s to text items 1 thru -2 of s as text

 

set the text item delimiters to tid

end try

 

return s

end __string__

 

# mouseLocation()

# Gets the current cursor position relative to the top-left corner of the

# screen

on mouseLocation()

script

use framework "Foundation"

use framework "AppKit"

 

property this : a reference to current application

property parent : this

 

property NSEvent : a reference to NSEvent of this

property NSScreen : a reference to NSScreen of this

 

on mouseLocation()

set [list, [number, height]] to ¬

NSScreen's ¬

mainScreen()'s ¬

frame()

 

tell NSEvent's mouseLocation() to ¬

{its x, height - (its y)}

end mouseLocation

end script

 

result's mouseLocation()

end mouseLocation

---------------------------------------------------------------------------❮END❯

 

 

Actually, that's the only way you can do it, by trying to find UI Elements by their properties. But not all elements have all the properties defined, so you just have to figure out what the fastest way is to get at the UI Element you want. I would suggest diving into AppleScript, as it lets you do stuff like "give me the first element that has a property with the value X in this list". Also, try to understand and use the "try" statement, I use it a lot so that you can return gracefully from a script instead of throwing an error, and you can test several situations after each other.

 

I use UI Browser to inspect the user interface elements of applications. Crashes a lot, and can't handle some windows (like the floating Region window), but it still helps a lot.

 

Hey Speakerfood, did you ever work out if you can automate using AXIdentifiers? I've managed to write a few scripts for launching plugins and instruments from the Touch Bar and one for automated track colouring, group and buss assignment, all done with System Events in AppleScript and executed with a single click. But its scripted using the UIElement properties and XY locations. Im a complete novice with AppleScript but eager to find a way to automate the UI and would be really grateful for any tips :)

 

Cheers[

 

 

Link to comment
Share on other sites

  • 2 weeks later...

I've been using this for a while...try this applescript. It bumps region gain up 1db. For -1db just change 'increment' to 'decrement'.

I have this bound to a key command in Keyboard Maestro

 

 

tell application "System Events"

tell process "Logic Pro X"

 

increment slider 1 of row 8 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of (first window whose value of attribute "AXMain" is true)

end tell

end tell

Link to comment
Share on other sites

Thanks for sharing.

 

Note that it will not work however when you have a Movie or Quick Help in the inspector, or when you hide the Control Bar.

You need to add some checks to handle all possible combinations.

 

I've been using this for a while...try this applescript. It bumps region gain up 1db. For -1db just change 'increment' to 'decrement'.

I have this bound to a key command in Keyboard Maestro

 

 

tell application "System Events"

tell process "Logic Pro X"

 

increment slider 1 of row 8 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of (first window whose value of attribute "AXMain" is true)

end tell

end tell

Link to comment
Share on other sites

  • 2 months later...

Hello all

 

I just wanted to chip in that i use the Region Gain script all the time!

And I just recently fiddled with the use of this script to edit Fade In and Fade Out parameters.

I altered the original script above here to increase and decrease Fade In and Out by three different increment sizes,

and I assigned it to hotkeys by BTT.

 

Shift + 1 = Fade IN + 100

Shift + 2 = Fade IN + 400

Shift + 3 = Fade IN + 1000

Shift + 4/5/6 = Fade OUT + 100/400/1000

 

Shift + Opt + 1 = Fade in - 100

etcetcetc

 

NB: This is not based on the script that speakerfood has adapted for a project that includes a movie or theother, but this works for me:

 

FADING IN 1000 ( x + 1000)

tell application "System Events"
tell process "Logic Pro X"
	tell row 11 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of (first window whose name contains "- Tracks")
		set x to (get value of slider 1)
		set value of slider 1 to (x + 1000)
	end tell
end tell
end tell

 

FADING OUT ( x + 1000)

tell application "System Events"
tell process "Logic Pro X"
	tell row 13 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of (first window whose name contains "- Tracks")
		set x to (get value of slider 1)
		set value of slider 1 to (x + 1000)
	end tell
end tell
end tell

 

Hope this can be of use to anyone else :D

Link to comment
Share on other sites

I use a Stream Deck with the KMLink plugin for this. Here's what my buttons look like:

 

XbPae3L.png

 

The parameter is passed on as a TriggerValue to Keyboard Maestro, then passed to a variable which is used in the below Applescript. If you change "EqP (Equal Power Crossfade)" to "Out", you'll get fade in/out rather than fade in and EqP crossfade.

 

tell application "Keyboard Maestro Engine"
set FadeLengthAS to (getvariable "Fade_Length") as number
end tell

activate application "Logic Pro X"
tell application "System Events"
tell process "Logic Pro"
	
	set tracks_window to title of first window whose title contains "- Tracks"
	
	set value of slider 1 of row 11 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window to FadeLengthAS
	
	set value of slider 1 of row 13 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window to FadeLengthAS
	
	click pop up button 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
	
	delay 0.1
	
	click menu item "EqP (Equal Power Crossfade)" of menu of pop up button 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
	
end tell
end tell

 

Here are the Keyboard Maestro macros, which are also hosted as part of a longer Logic/KM/SD post.

 

Crossfade macro:

https://forum.keyboardmaestro.com/uploads/short-url/kkEBEum9rHvx2THb140geMVlEWX.kmmacros

Fade macro:

https://forum.keyboardmaestro.com/uploads/short-url/eoh60tYufJaUB8D8mG8yYJzw7om.kmmacros

Link to comment
Share on other sites

  • 1 year later...
On 11/26/2020 at 3:20 PM, eliottsigg said:

Hello,

I'm very interested in making this applescript work and triggering it with Bettertouchtool.

I would love to assign it to a trackpad gesture (for example : ctrl+scroll up = raise region gain).

 

But I have a problem when I try and run the script :

Error in system events : impossible to obtain window 1 of process "Logic Pro X" whose title contains "- Tracks". Index non valable. number -1719

 

I'm wondering if it might come from the fact that I'm running logic pro in french ?

This my first time working with an applescript so I'm a bit lost.

I'm running logic pro 10.5.1

 

Thanks for your help !

Hi - Did you ever manage to figure this out?

Am using Keyboard Maestro and it doesn't seem to recognise a trackpad gesture as a hotkey command!

 

Let me know if you did!

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...