Jump to content

Set Audio MIDI Setup to connect bluetooth device


Recommended Posts

Hi there! My ever first topic here, and asking for some knowledge…

I'm trying to figure out how to setup what's in the Topic's Title. The thing is that it involves some actions and triggers, I guess, by going to the Audio MIDI Setup app > MIDI Studio > Open Bluetooth Configuration… > and hit the Connect button. Is there a way to record a macro or to achieve this within Alfred?

Thanks in Advance

Cheers,

Link to comment

Hi @xattr, welcome to the forum.

 

This isn't really something Alfred can help much with: it's a launcher, not an automation app, and it's ability to make other apps do things doesn't extend much beyond telling them to open files or URLs.

 

If you want to make another application do something from Alfred, you basically first need to write a script or program to make the app do what you want, and then Alfred can run it for you.

 

You might be able to do what you want with the proper MIDI APIs. If not, you're going to have to simulate mouse and menu clicks, which looks pretty difficult to do in this case. Something like Keyboard Maestro (which is designed for this kind of thing) might be able to do it more easily.

Link to comment

@xattr You will be able to get most of the way there with a simple workflow in Alfred.

 

Add a Hotkey or Keyword object to a workflow, then connect this to a Run Script object set to osascript (AppleScript), then paste in the following:

 

on run argv
	tell application "Audio MIDI Setup" to activate
	tell application "System Events" to tell process "Audio MIDI Setup"
		try
			click menu item "Show MIDI Studio" of menu 1 of menu bar item "Window" of menu bar 1
		end try
		delay 0.2
		click menu item "Open Bluetooth Configuration…" of menu 1 of menu bar item "MIDI Studio" of menu bar 1
	end tell
end run

 

This will take you to the midi bluetooth connection screen. I don't have any bluetooth midi devices, so can't actually see a connect button.

 

For a bit of an explanation of the above script, it opens the Audio Midi setup, then clicks the "Show Midi Studio" item in the menu. This is wrapped in a try block because the menu item is "Hide Midi Studio" if it's already showing. The following delay allows time for this window to show, and the new menu item of "Midi Studio" to be added to the top of macOS. Finally, click the "Open Bluetooth Configuration…" button of the Midi Studio menu.

 

Hope this helps,

Andrew

Link to comment
2 hours ago, deanishe said:

Hi @xattr, welcome to the forum.

 

This isn't really something Alfred can help much with: it's a launcher, not an automation app, and it's ability to make other apps do things doesn't extend much beyond telling them to open files or URLs.

 

If you want to make another application do something from Alfred, you basically first need to write a script or program to make the app do what you want, and then Alfred can run it for you.

 

You might be able to do what you want with the proper MIDI APIs. If not, you're going to have to simulate mouse and menu clicks, which looks pretty difficult to do in this case. Something like Keyboard Maestro (which is designed for this kind of thing) might be able to do it more easily.

Hi,

yeah, I know Keyboard Maestro has the ability to do this kind of workflows but I wasn’t able to achieve it, probably with a script as mentioned by @Andrew! Which I will try just inside Alfred.

 

46 minutes ago, Andrew said:

@xattr You will be able to get most of the way there with a simple workflow in Alfred.

 

Add a Hotkey or Keyword object to a workflow, then connect this to a Run Script object set to osascript (AppleScript), then paste in the following:

 

on run argv
	tell application "Audio MIDI Setup" to activate
	tell application "System Events" to tell process "Audio MIDI Setup"
		try
			click menu item "Show MIDI Studio" of menu 1 of menu bar item "Window" of menu bar 1
		end try
		delay 0.2
		click menu item "Open Bluetooth Configuration…" of menu 1 of menu bar item "MIDI Studio" of menu bar 1
	end tell
end run

 

This will take you to the midi bluetooth connection screen. I don't have any bluetooth midi devices, so can't actually see a connect button.

 

For a bit of an explanation of the above script, it opens the Audio Midi setup, then clicks the "Show Midi Studio" item in the menu. This is wrapped in a try block because the menu item is "Hide Midi Studio" if it's already showing. The following delay allows time for this window to show, and the new menu item of "Midi Studio" to be added to the top of macOS. Finally, click the "Open Bluetooth Configuration…" button of the Midi Studio menu.

 

Hope this helps,

Andrew

Thanks @Andrew, I’ll try that and report back. :)

Link to comment
Just now, xattr said:

Which I will try just inside Alfred

 

It’s generally easier to write the script in Script Editor then move it over to Alfred once it’s working. Also, when you do, use a Run Script with Language = /usr/bin/osascript (AS), not Run NSAppleScript.

 

Link to comment
Posted (edited)

Everything goes as it should until the Connect button click, it does nothing on that button…

I’m really knocking my head on the wall and since it’s not an Alfred related question I’ll keep researching and trying and will post later the solution.

What I tried so far:

- applied the suggest script which stops before the button click and tried also with other syntax…

- record the actions within Automator which works flawlessly inside it but the app it generates stops when it goes to the menu to choose Open Bluetooth Configuration… weird!

- finally tried to copy the actions recorded from Automator to ScriptEditor and paste them in the script inside Alfred but nothing happens…

Edited by xattr
Link to comment
5 hours ago, xattr said:

Everything goes as it should until the Connect button click, it does nothing on that button…

 

Yeah, Andrew's script doesn't do that part because – like he said – he has no MIDI devices and therefore no "connect" button.

 

Could you post a screenshot of the Audio MIDI Setup app at the end of the script? We might be able to provide a simple fix. No promises, though: It was the "hit the connect button" part that made me suggest Keyboard Maestro to start with.

Link to comment

Is there a key combination you can use to select the device and then connect? Say ↓ to select, then a key combo or menu item for "connect"?

 

Otherwise, you'll probably have use Accessibility Inspector (part of Xcode) to dig through the UI to find the element to simulate a click on.

 

Personally, I'd just use Keyboard Maestro. It can run the AppleScript Andrew gave you, and you can literally take a screenshot of the device list and tell it to click on the "Connect" button (Click at Found Image).

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...