Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple script additions #457

Merged
merged 11 commits into from
Mar 24, 2021
Merged

Apple script additions #457

merged 11 commits into from
Mar 24, 2021

Conversation

marcuswu
Copy link
Contributor

These changes allow for additional scripting such as:

tell application "Background Music"
	set selected output device to first output device whose name is equal to "Built-in Output"
	
	set vol of (a reference to (the first audio application whose name is equal to "zoom.us")) to 75
	set pan of (a reference to (the first audio application whose name is equal to "zoom.us")) to 0
	
	set output volume to 0.5
end tell

#326
#449

@kyleneideck
Copy link
Owner

Sorry, only just saw this. I've had a quick read through most of it and it looks great. I'll try to read it properly and test it out tomorrow so I can merge it.

@kyleneideck
Copy link
Owner

I left a few more comments about tiny things, but I've finished reading through the code and tested it and it all looks good to me. Happy to merge it whenever you're ready.

@kyleneideck kyleneideck merged commit c0a556b into kyleneideck:master Mar 24, 2021
@kyleneideck
Copy link
Owner

Merged, thanks again. I've been wanting to add these features to the AppleScript API for ages, so I'm very happy to get this PR in.

@chinarui-na
Copy link

These changes allow for additional scripting such as:

tell application "Background Music"
	set selected output device to first output device whose name is equal to "Built-in Output"
	
	set vol of (a reference to (the first audio application whose name is equal to "zoom.us")) to 75
	set pan of (a reference to (the first audio application whose name is equal to "zoom.us")) to 0
	
	set output volume to 0.5
end tell

#326
#449

i try it . but receive err:
can not get audio application 1 whose name = "zoom.us

@kyleneideck
Copy link
Owner

Did you try some other apps? Maybe it's just not working for Zoom for some reason. I only tested it with Music.app. (Used to be called iTunes.app.)

@chinarui-na
Copy link

i try Music. same to zoom.us
code is :

tell application "Background Music"
	set selected output device to first output device whose name is equal to "Built-in Output"
	
	set vol of (a reference to (the first audio application whose name is equal to "Music")) to 75
	set pan of (a reference to (the first audio application whose name is equal to "Music")) to 0
	
	set output volume to 0.5
end tell

result is :error "“Background Music”遇到一个错误:不能获得“audio application 1 whose name = "Music"”。无效的索引。"

@kyleneideck
Copy link
Owner

Maybe the app name is localized for you. Is it called "Music" in the menu in Background Music?

You can list all of the apps like this:

tell application "Background Music"
	get the name of every audio application
end tell

Is "Music" one of the names in that list for you?

@marcuswu
Copy link
Contributor Author

Oh, that's very true -- I am using the localized app name property so any internationalization in the app name will affect how to reference an application.

@chinarui-na
Copy link

That's true. Music display in Chinese '音乐'.Now it run success. Thank you very much.

@kyleneideck
Copy link
Owner

I just added a bundle ID property, so now you have the option of looking up the app by its bundle ID as well:

tell application "Background Music"
	-- get the bundleID of every audio application
	set vol of (a reference to (the first audio application whose bundleID is equal to "com.apple.Safari")) to 15
end tell

I think the bundle ID should be pretty stable for most apps and it won't be localized, so it might work better, depending on your use case. Or you could try one and fallback to the other if it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants