Automatically Mute iPhone At Work
Posted on May 30, 2024
I always feel nervous at work that I may forget to mute my iPhone, leave it on the table and leave to get some coffee. During this time, my phone may ring and disturb my colleagues. I don't want to disturb whole office with my ringtone. I also don't want to miss any important calls after the work. So I decided to automate it using Apple Shortcuts.
I've created a shortcut that saves current volume to file in iCloud, then automatically mutes my iPhone when I arrive at work. Then I've created another shortcut that unmutes it when I leave and restores previous volume level.
Here's how I did it.
Store Volume And Mute Shortcut
- Get the Current Volume: This action retrieves the current volume level of the device.
- Set Variable: This action sets a variable named
volume
to the current volume level retrieved by the previous action. - If Statement: This checks if the value of
volume
is greater than 0. If true, it triggers the actions within the if statement. - Save ‘volume’ to Shortcuts: The value of the
volume
variable is saved to a file within the Shortcuts app. The path specified isVolumeUpdater/previous-volume.txt
, and the file will be overwritten if it exists. - Set Ringtone Volume to 0%: This action sets the device’s ringtone volume to 0%, effectively muting it.
- Set Media Volume to 0%: Similar to the previous action, this sets the media volume to 0%.
- Otherwise: It seems there are no actions specified for the case where
volume
is not greater than 0. - End If: Marks the end of the if statement.
This shortcut essentially saves the current volume level and mutes the device if the volume was previously above 0.
Restore Volume Shortcut
- Get File from Shortcuts: Retrieves a file named
VolumeUpdater/previous-volume.txt
from a specified path within the Shortcuts app. If the file is not found, an error will occur. - Set Variable: Assigns the contents of the retrieved file to a variable named
volume
. - If Statement: Checks if the
volume
variable has any value. If it does, it triggers the actions within the if statement. - Set Ringtone Volume: Sets the device’s ringtone volume back to the level stored in the
volume
variable. - Set Media Volume: Similarly, sets the device’s media volume back to the level stored in the
volume
variable. - Otherwise: There appear to be no actions specified for the case where the
volume
variable does not have a value. - End If: Marks the end of the if statement.
This shortcut effectively restores the device’s ringtone and media volume to the levels they were at before they were muted, assuming the volume was previously saved and the file exists.
Automate Muting and Unmuting
To automate the muting and unmuting process, I used Focus mode in iOS. I created a Work Focus mode that activates when I arrive at work and deactivates when I leave. The Work Focus mode triggers the Store Volume And Mute Shortcut when activated and the Restore Volume Shortcut when deactivated.
To trigger the shortcuts, I used the Automation feature in Shortcuts. I created two automations: one when Work Focus mode is turned on and another when it is turned off. The automations run the respective shortcuts when triggered.
Conclusion
- You can download "Save Mute Volume" Shortcut using link here.
- You can download "Restore Volume" Shortcut using link here.
Automations can't be shared and you need to configure them manually.
This automation has been working well for me, and I no longer have to worry about muting my iPhone when I arrive at work.