GUI scripting with Garageband X- Can't identify button

Hi all, I’m new to this applescript and its looking all quite interesting. I have been playing around with Garageband and wanted to be able to script the turning on and off of the pedals for the guitar rig. You can add different pedals (that have different arrangements of buttons and sliders on each pedal) and reorder their position.

This is the basic script to turn on the first pedal in the series of pedals


activate application "GarageBand"
tell application "System Events"
	tell process "GarageBand"
		click button 4 of window 1
	end tell
end tell

This is the inspector details for the button on the pedal
<AXApplication: “GarageBand”>
<AXWindow: “Guitar 1”>
<AXButton: “”>

Attributes:
AXRole: “AXButton”
AXRoleDescription: “button”
AXHelp: “(null)”
AXEnabled: “1”
AXFocused (W): “0”
AXParent: “<AXWindow: “Guitar 1”>”
AXWindow: “<AXWindow: “Guitar 1”>”
AXTopLevelUIElement: “<AXWindow: “Guitar 1”>”
AXPosition: “x=664.603 y=265.767”
AXSize: “w=76 h=66”
AXTitle: “”
AXIdentifier: “_NS:380”

Actions:
AXPress - press

I have been able to turn the buttons on using applescript, but the problem is that if you move the position of a pedal, the buttons are not referenced to pedal, but the position where the button is located relative to the other buttons on the other pedals.

ie: button 4 turns on pedal A, button 7 turns on pedal B, button 9 turns of pedal C
(A,B,C)

If you move pedal C in front of pedal A (C,A,B), then button 4 turns on C, but now (for example) button 6 turns on pedal A and button 8 turns on pedal B

Using the Accessibility Inspector, I can move the pedal into a different position and it will still identify with the button. How do I translate this into the script? I can’t seem to find any unique identifier for the button itself! I thought it might be the AXidentifier, but all the buttons have the same identity.

Thanks all for your help, i think my post has been a bit long winded!

Richard

As it was written many times, Yosemite is lazy so when we ask it to activate an application, there is a long delay before its availability at front.
Of course we may insert a delay but the neater scheme is to explicitly push the application process at front.

Try with :

activate application "GarageBand"
tell application "System Events"
	tell process "GarageBand"
		set frontmost to true # ADDED
		click button 4 of window 1
	end tell
end tell

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) vendredi 25 septembre 2015 10:31:00

Thanks for the reply. The availability of the window is not an issue, the script will activate the button in the active window (no delay), but i’m trying to work out how to identify the button itself. The inspector doesn’t give me enough info as to what the button is.

Richard

As I don’t use GarageBand, I ran it once and ran the piece of code which I use when I must trigger GUIScripting.

What I got doesn’t match what you described but you may use the same kind of code to get infos allowing your script to see which pedal is active.

activate application "GarageBand"
tell application "System Events"
	tell process "GarageBand"
		set frontmost to true # ADDED
		
		log (get class of UI elements)
		(*window, window, menu bar*)
		tell window 1
			log (get its name)
			(**)
			log (get properties of UI elements)
			(*
			class:slider, minimum value:0.0, orientation:AXHorizontalOrientation, position:1389, 635, role description:curseur, accessibility description:missing value, focused:false, title:missing value, size:63, 25, value:0.120663106441, help:Zoom horizontal, enabled:true, maximum value:1.0, role:AXSlider, entire contents:, subrole:missing value, selected:missing value, name:missing value, description:curseur*)
			log (get attributes of UI element 1)
			(*
			attribute AXEnabled of slider 1 of window 1 of application process GarageBand, 
			attribute AXAllowedValues of slider 1 of window 1 of application process GarageBand, 
			attribute AXOrientation of slider 1 of window 1 of application process GarageBand, 
			attribute AXParent of slider 1 of window 1 of application process GarageBand, 
			attribute AXSize of slider 1 of window 1 of application process GarageBand, 
			attribute AXFocused of slider 1 of window 1 of application process GarageBand, 
			attribute AXChildren of slider 1 of window 1 of application process GarageBand, 
			attribute AXRole of slider 1 of window 1 of application process GarageBand, 
			attribute AXTopLevelUIElement of slider 1 of window 1 of application process GarageBand, 
			attribute AXHelp of slider 1 of window 1 of application process GarageBand, 
			attribute AXPosition of slider 1 of window 1 of application process GarageBand, 
			attribute AXValue of slider 1 of window 1 of application process GarageBand, 
			attribute AXWindow of slider 1 of window 1 of application process GarageBand, 
			attribute AXRoleDescription of slider 1 of window 1 of application process GarageBand, 
			attribute AXMinValue of slider 1 of window 1 of application process GarageBand, 
			attribute AXMaxValue of slider 1 of window 1 of application process GarageBand, 
			attribute AXFrame of slider 1 of window 1 of application process GarageBand*)
			log (get properties of attributes of UI element 1)
			(*
			class:attribute, value:true, settable:false, name:AXEnabled, 
			class:attribute, value:missing value, settable:false, name:AXAllowedValues, 
			class:attribute, value:AXHorizontalOrientation, settable:false, name:AXOrientation, 
			class:attribute, value:missing value, settable:true, name:AXParent, 
			class:attribute, value:63, 25, settable:false, name:AXSize, 
			class:attribute, value:false, settable:true, name:AXFocused, 
			class:attribute, value:value indicator 1 of slider 1 of window 1 of application process GarageBand, settable:false, name:AXChildren, 
			class:attribute, value:AXSlider, settable:false, name:AXRole, class:attribute, value:missing value, settable:false, name:AXTopLevelUIElement, 
			class:attribute, value:Zoom horizontal, settable:false, name:AXHelp, 
			class:attribute, value:850, 113, settable:false, name:AXPosition, 
			class:attribute, value:0.180662930012, settable:true, name:AXValue, 
			class:attribute, value:window 1 of application process GarageBand, settable:false, name:AXWindow, 
			class:attribute, value:curseur, settable:false, name:AXRoleDescription, 
			class:attribute, value:0.0, settable:false, name:AXMinValue, 
			class:attribute, value:1.0, settable:false, name:AXMaxValue, 
			class:attribute, value:850, 113, 913, 138, settable:false, name:AXFrame*)
			--click button 4
		end tell
		tell window 2
			log (get its name)
			(*Sans Nom - Pistes*)
			log (get properties of UI elements)
			(*class:button, minimum value:missing value, orientation:missing value, position:-521, 26, role description:Bouton de fermeture, accessibility description:missing value, focused:false, title:missing value, size:14, 16, value:missing value, help:missing value, enabled:true, maximum value:missing value, role:AXButton, entire contents:, subrole:AXCloseButton, selected:missing value, name:missing value, description:Bouton de fermeture, 
			class:button, minimum value:missing value, orientation:missing value, position:-481, 26, role description:bouton plein écran, accessibility description:missing value, focused:false, title:missing value, size:14, 16, value:missing value, help:ce bouton peut également agrandir ou réduire la fenêtre, enabled:true, maximum value:missing value, role:AXButton, entire contents:, subrole:AXFullScreenButton, selected:missing value, name:missing value, description:bouton plein écran, 
			class:button, minimum value:missing value, orientation:missing value, position:-501, 26, role description:Bouton de placement dans le Dock, accessibility description:missing value, focused:false, title:missing value, size:14, 16, value:missing value, help:missing value, enabled:true, maximum value:missing value, role:AXButton, entire contents:, subrole:AXMinimizeButton, selected:missing value, name:missing value, description:Bouton de placement dans le Dock, 
			class:image, minimum value:missing value, orientation:missing value, position:139, 26, role description:image, accessibility description:missing value, focused:false, title:Sans Nom.band, size:16, 16, value:missing value, help:missing value, enabled:true, maximum value:missing value, role:AXImage, entire contents:, subrole:missing value, selected:missing value, name:Sans Nom.band, description:image, 
			class:static text, minimum value:missing value, orientation:missing value, position:157, 25, role description:texte, accessibility description:missing value, focused:false, title:missing value, size:119, 17, value:Sans Nom - Pistes, help:missing value, enabled:true, maximum value:missing value, role:AXStaticText, entire contents:, subrole:missing value, selected:missing value, name:Sans Nom - Pistes, description:texte, 
			class:group, minimum value:missing value, orientation:missing value, position:-509, 49, role description:barre d'outils, accessibility description:Barre des commandes, focused:false, title:missing value, size:1433, 48, value:missing value, help:missing value, enabled:missing value, maximum value:missing value, role:AXGroup, entire contents:, subrole:missing value, selected:missing value, name:missing value, description:Barre des commandes, 
			class:group, minimum value:missing value, orientation:missing value, position:-513, 107, role description:groupe, accessibility description:missing value, focused:false, title:missing value, size:382, 939, value:missing value, help:missing value, enabled:missing value, maximum value:missing value, role:AXGroup, entire contents:, subrole:missing value, selected:missing value, name:missing value, description:groupe, 
			class:splitter group, minimum value:missing value, orientation:missing value, position:-129, 107, role description:diviser groupe, accessibility description:missing value, focused:false, title:missing value, size:1057, 940, value:missing value, help:missing value, enabled:missing value, maximum value:missing value, role:AXSplitGroup, entire contents:, subrole:missing value, selected:missing value, name:missing value, description:diviser groupe*)
		end tell
	end tell
end tell

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 30 septembre 2015 11:11:14