I have particular EQ settings I like to use for my speakers at home, however when I'm using my laptop speakers or Bluetooth headphones I prefer to have a flat EQ. Is there a way to specify different EQ settings for each audio output and automatically switch to the correct setting when the audio output is changed?
-
1Are you looking to use Automator to script your mouse - select the are output - select the application (presumably iTunes) then select the EQ? That all should be doable with Apple's automation tools.– bmike ♦Commented Mar 25, 2018 at 15:09
-
Thanks, I realised that adjusting just the iTunes EQ would probably be sufficient for my needs, which is simple to adjust from AppleScript.– shearnonsenseCommented Mar 25, 2018 at 15:29
-
Great question - and even better answer - +1 all around– bmike ♦Commented Mar 25, 2018 at 15:41
1 Answer
Reading the current audio output gives "Built-in Output" for both headphones and internal speakers, however we need to be able to tell between headphones and speakers. In order to do this, you can use code from this answer to create a program that checks whether headphones are plugged in or another audio output is in use:
#include <CoreAudio/CoreAudio.h>
#include <iostream>
void updateEQ() {
AudioDeviceID defaultDevice = 0;
UInt32 defaultSize = sizeof(AudioDeviceID);
const AudioObjectPropertyAddress defaultAddr = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultAddr, 0, NULL, &defaultSize, &defaultDevice);
AudioObjectPropertyAddress property;
property.mSelector = kAudioDevicePropertyDataSource;
property.mScope = kAudioDevicePropertyScopeOutput;
property.mElement = kAudioObjectPropertyElementMaster;
UInt32 dataSourceId = 0;
UInt32 dataSourceIdSize = sizeof(UInt32);
AudioObjectGetPropertyData(defaultDevice, &property, 0, NULL, &dataSourceIdSize, &dataSourceId);
if (dataSourceId == 'hdpn') {
std::cout << "Changed to headphones" << std::endl;
system("osascript <<path to speaker EQ script>>");
} else {
std::cout << "Changed to not headphones" << std::endl;
system("osascript <<path to other EQ script>>");
}
}
int main(int argc, const char * argv[])
{
updateEQ();
return 0;
}
Each EQ script is then a simple AppleScript script that updates iTunes's EQ, for example the speaker EQ script is:
tell application "iTunes"
set current EQ preset to (get first EQ preset whose name is "Speakers")
set EQ enabled to true
end tell