Background
The current behavior for the Volume Up/Down
keys is to adjust the system volume in whole increments. But! The key combo Option(Alt)+Shift+Volume Up/Down
will change the volume in 1/4 increments. Perfect! Except a pain.
The Goal
I'd like to remap / intercept / override the behaviour of the Volume Up/Down
keys to either:
Automatically adjust the volume in 1/4 increments
A setting, file or script that I could write or modify to set this as default behaviour would be ideal!
Mimic
Option(Alt)+Shift+Volume Up/Down
being pressedI press one key (
Volume Up/Down
), but the system sees that I've pressed the three-key combo!
Caveats
With the aforementioned end-goal, Imma nitpick a little.
No third-party software (TPS)
If a TPS can remap the keys on my system, or intercept key presses and perform tasks, then a well-written AppleScript or BashScript can do the same.
There are many reasons for not wanting TPS, but mostly I like to roll my own (when I can), and don't want an entire app for one single change.
Cannot have Use all F1, F2, etc. keys as standard function keys. enabled
This one is important. I do not want to override the
F11
andF12
keys - I want to override theVolume Up
andVolume Down
keys.I use all of the other
special feature keys
often. Having to press thefn
key to control music playback, or change my screen brightness, is not an acceptable compromise to have the desired volume behavior.
So Far
So far, all I've been able to find are links telling me how to fine-tune the volume (by pressing the 3-key combo). I'd link to them - to prove my due-diligence before asking a question - but they're all the same as the one I linked above. Nothing alluding to setting it as the default behavior.
As for remapping the keys, I keep coming up with only a couple methods:
Third-party software (like Karabiner)
This won't do. Read above.
Creating custom shortcuts in System Preferences
I'm fine using this method, but what would I enter for the
Menu Title
to refer to the fine-adjustment volume control? Also, when I've tried to do this (just tried it now), when I place the cursor in theKeyboard Shortcut
box and press theVolume Up/Down
buttons, it just changes the volume, instead of populating the input with the key pressed.
Final Thoughts
A custom script (Bash, AppleScript, other), modifying a system file hiding somewhere, or whatever you've got - I'll take it!
Thanks in advance!
EDIT #1 - Some Progress
Semi-Working
The default volume control has 17 levels (with the 17th being zero). The volume is set as an integer value, out of 100. This means the default volume change is around 6% per level.
I was able to use Automator to create a couple services, that change the volume in increments of 1%. The services are a single Run AppleScript
within the workflow.
--Volume Up AppleScript
set vol to output volume of (get volume settings)
if vol > 100 then # 100 is max
set volume output volume 100
else
set volume output volume (vol + 1)
end if
do shell script "afplay /System/Library/Sounds/Pop.aiff"
And then you can bind a hotkey to it in System Preferences (refer to original question). There are two issues I'm having though:
Still cannot bind special-function keys to service
When I go try to use the
Volume Up/Down
keys to set the shortcut, it just changes the volume, without registering the key pressed.I went into
~/Library/Preferences/pbs.plist
, and tried to change the key manually, fromto
Note: Key Code
71
and72
are forVolume Down
andVolume Up
special function keys, respectively.The screenshots above were taken from PlistBuddy in terminal. The weird question-mark-looking symbol is the exact same when viewing the value in XCode.
I cannot find the link right now, but it seems that macOS Sierra is not working with the special-function key codes. Otherwise, a simple AppleScript could have forced the single key press into the 3-key combo:
tell application "System Events" to key code 72 using {shift down, option down}
Spoiler alert... it doesn't work. And interestingly enough, when I run the script, an equal-sign (
=
) is inserted wherever the live cursor is.Not all key codes do this. For instance,
81
will also insert an equal-sign, but82
enters a zero (0
) - both of which correspond to the key codes in the link above. So maybe macOS Sierra has completely gone away from assigning codes to the special function keys? Or they've changed?Cannot get the Apple Volume Beze to appear when changing the volume
You can disable the bezel, but I cannot find anywhere a way to programatically call it. Ideally, it would just be an additional line, after
do shell script ...
in the Automator AppleScript above.I'm honestly not too concerned with the bezel, but would like some way to know the current volume setting.
Menu Bar Icon
A perfectly acceptable solution would be to display the current volume setting (numerical) in the menu bar. But I could not find any pre-existing numerical volume icon.
I tried looking into modifying the current menu bar volume icon script to display the numerical value instead of the speaker icon, but couldn't get anywhere with that. (The path that I found for it is at
/System/Library/CoreServices/Menu Extras/Volume.menu/Contents
, if anyone thinks they've got a solution). Otherwise, I might try my hand at creating my own menu bar icon.Screen Overlay
I also tried looking into creating a pop-up, semi-transparent overlay what would display the current volume setting and then fade out (on top of all other screen content). The functionality would be the same as the stock volume bezel, but maybe just a number in the corner of the screen.
You can create notifications with AppleScripts, but they are way too big for a small 1-, 2- or 3-digit number, are not transparent, and linger too long. The behavior of an overlay would have to be overwriting the current overlay with a new one, displaying the new value. Using notifications, I would just get a stack of lingering notifications.
Other Attempts
I also looked into modifying the audio drivers, hoping that there would be a default setting that I could change. The most promising files I could find are at:
/System/Library/Frameworks/AudioToolbox.framework
and
/System/Library/Frameworks/AudioUnit.framework
but I couldn't find anything in any of the files within, that might be modified to change the number of volume steps from 17 to 100.
**
Thanks for making it this far! It's long, but I want to make sure that I've presented everything I know, and everything I've tried.