0

I'm using a 14 inch M1 Pro Macbook Pro, running Mac OS Monterey 12.6.

I'm making an OpenCV and Mediapipe based Computer Vision Project that allows me to use hand detection to control my Mac's volume. The code detects the distance between the tips of my index finger and thumb using the webcam, and changes the volume based on that. I've been trying to use osascript to set the volume:

        osascript.osascript("set volume output volume 0")

It works, but only for hard coded values like 0, 5 and 10. How do I pass a variable value N to osascript:

osascript.osascript("set volume output volume N")

If I could pass that variable value, then I could actually vary the volume instead of having it set at either 0, 5 or 10. The documentation hasn't been very helpful, anybody have any ideas or alternatives instead of osascript?

I've tried applescript but couldn't figure it out.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85

2 Answers2

0

I'm guessing you are actually using Python, though you don't mention it in the question or in your tags.

If so, you can use an "f-string" like this - note the f at the start:

N = 7
osascript.osascript(f"set volume output volume {N}")
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

Use command

osascript -e "set Volume 10"

or use python library driver_controler https://github.com/Alexandro1112/driver-controller

  • When linking to your own site or content (or content that you are affiliated with), you [must disclose your affiliation _in the answer_](/help/promotion) in order for it not to be considered spam. Having the same text in your username as the URL or mentioning it in your profile is not considered sufficient disclosure under Stack Exchange policy. – cigien Feb 18 '23 at 17:29