Creation of Shortcut Automation

As one of the most powerful applications from Apple, it's quite disappointing due to official limitations.

I would like to create an automation that checks whether AirPods are connected when the app is opened or closed. If AirPods are connected, it does nothing; otherwise, it sets the media volume to 50%. When the app is closed and AirPods are not connected, it sets the media volume to 0%.

However, I can only achieve this by:

1. Creating an automation that "when AirPods are connected, copies the text 'AirPods Connected' to the clipboard";

2. Creating an automation that "when the app is opened, if the clipboard does not contain 'AirPods Connected', sets the media volume to 50%";

3. Creating an automation that "when the app is closed, if the clipboard does not contain 'AirPods Connected', sets the media volume to 0%".

This operation is very cumbersome, and if the clipboard is overwritten, these three automations will fail to run.

I hope there can be some relaxation of system permissions, such as being able to read connected Bluetooth devices, whether the app is open, and so on.

thanks.

iPhone 13 mini, iOS 17

Posted on May 27, 2024 2:40 AM

Reply
4 replies

May 31, 2024 5:58 PM in response to 5p6X5rWp

Instead of using the clipboard, use another data persistence mechanism.


You can do it using data written to a file in iCloud:

  • The "AirPods Connected" personal automation writes the string "AirPods connected" to the file.
  • The "AirPods Disconnected" personal automation writes the string "AirPods disconnected" to the file.
  • The "App Open" personal automation reads the file and, using an "If" action decides what to do.
  • The "App Close" personal automation reads the file and, using an "If" action decides what to do.


An easier way to persist data (besides storing the AirPods state in a file) is to use the Data Jar application from the App Store. You'd need the same numbers of automation as above but you'd only need to store and retrieve the state through to Data Jar.

May 27, 2024 3:19 AM in response to 5p6X5rWp

You need to do this in two steps.

  1. Create a Shortcut as shown in the pic 1
  2. Create automation and call the Shortcut created - Pic 2


Open the Music app and your music automation will seamlessly start playing through your AirPods. If your AirPods aren't securely in your ears, the music will pause briefly while the automation searches for them. Once reconnected, playback will resume, just like the Music app normally behaves.


Enjoy!



Pic 1



Pic 2

May 27, 2024 8:10 AM in response to SravanKrA

No, no, no, my usage scenario is:

First, the volume is usually 0%, and then the volume is automatically set to 50% when opening a specific application, and the volume off the application is returned to 0%.

Second, when I wear AirPods, the volume is 100% (I set the headphone safety and reduce the high-sound audio to 80 decibels).

Third, if I open a specific app when wearing AirPods, the volume will automatically drop to 50%, and turning off the app will reduce the volume to 0%.

Therefore, the basic requirement for I want to achieve automation is that when I open a specific application, if I wear headphones, the volume will remain unchanged; if I don't wear headphones, the volume will automatically increase from 0% to 50%. When turning off the app, if I wear headphones, the volume will remain unchanged; if I don't bring headphones, the volume will be automatically adjusted to 0%.

This requires identification of whether the device is connected to AirPods or whether I have opened a specific app. But Apple has limited it!

May 31, 2024 7:48 PM in response to 6x6

Thank you very much. The method I use now is that the volume will be automatically set to 100% when I put on the headphones, and the volume will be automatically set to 0% when I put down the headphones. Set the shortcut according to this feature: read the current volume when opening the application, and if the volume is 1, skip it; otherwise, set the volume to 50%. If you close the app, set the volume to 0. But there are still flaws. Now after reading your advice, I am suddenly enlightened! 🙏

Creation of Shortcut Automation

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.