Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7432073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:23:55+00:00 2026-05-29T09:23:55+00:00

Does anyone know if it’s possible to create a listener to detect when a

  • 0

Does anyone know if it’s possible to create a listener to detect when a Macs system volume changes? If so do you know where I can find an example on how to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:23:55+00:00Added an answer on May 29, 2026 at 9:23 am

    Concept

    So, hopefully there’s a better way to deal with this, but this is a concept:

    Spin off a new thread to watch the volume attribute found in AudioToolbox. Then have it call a callback of some kind.

    #import "AppDelegate.h"
    #define kVolumeKey @"currentvolumeforvolumemonitorkey"
    
    @implementation AppDelegate
    
    @synthesize window = _window;
    
    /* Credit to CocoaDev Starts Now */
    /* http://www.cocoadev.com/index.pl?SoundVolume */
    +(AudioDeviceID)defaultOutputDeviceID
    {
        AudioDeviceID   outputDeviceID = kAudioObjectUnknown;
        
        // get output device device
        UInt32 propertySize = 0;
        OSStatus status = noErr;
        AudioObjectPropertyAddress propertyAOPA;
        propertyAOPA.mScope = kAudioObjectPropertyScopeGlobal;
        propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
        propertyAOPA.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
        
        if (!AudioHardwareServiceHasProperty(kAudioObjectSystemObject, &propertyAOPA))
        {
            NSLog(@"Cannot find default output device!");
            return outputDeviceID;
        }
        
        propertySize = sizeof(AudioDeviceID);
        
        status = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAOPA, 0, NULL, &propertySize, &outputDeviceID);
        
        if(status) 
        {
            NSLog(@"Cannot find default output device!");
        }
        return outputDeviceID;
    }
    
    +(float)volume 
    {
        Float32         outputVolume;
        
        UInt32 propertySize = 0;
        OSStatus status = noErr;
        AudioObjectPropertyAddress propertyAOPA;
        propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
        propertyAOPA.mSelector = kAudioHardwareServiceDeviceProperty_VirtualMasterVolume;
        propertyAOPA.mScope = kAudioDevicePropertyScopeOutput;
        
        AudioDeviceID outputDeviceID = [AppDelegate defaultOutputDeviceID];
        
        if (outputDeviceID == kAudioObjectUnknown)
        {
            NSLog(@"Unknown device");
            return 0.0;
        }
        
        if (!AudioHardwareServiceHasProperty(outputDeviceID, &propertyAOPA))
        {
            NSLog(@"No volume returned for device 0x%0x", outputDeviceID);
            return 0.0;
        }
        
        propertySize = sizeof(Float32);
        
        status = AudioHardwareServiceGetPropertyData(outputDeviceID, &propertyAOPA, 0, NULL, &propertySize, &outputVolume);
        
        if (status)
        {
            NSLog(@"No volume returned for device 0x%0x", outputDeviceID);
            return 0.0;
        }
        
        if (outputVolume < 0.0 || outputVolume > 1.0) return 0.0;
        
        return outputVolume;
    }
    /* Thanks CocoaDev! */
    
    
    - (void)dealloc
    {
        [super dealloc];
    }
    
    - (void)volumeDidChangeToLevel: (CGFloat)level
    {
        NSLog(@"LEVEL: %f", level);
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
        ^{
            [[NSUserDefaults standardUserDefaults] setFloat: [[self class] volume] forKey: kVolumeKey];
            [[NSUserDefaults standardUserDefaults] synchronize];
            for(CGFloat volLevel = [[self class] volume];; volLevel = [[self class] volume])
            {
                 if (volLevel != [[NSUserDefaults standardUserDefaults] floatForKey: kVolumeKey])
                 {
                     [[NSUserDefaults standardUserDefaults] setFloat: [[self class] volume] forKey: kVolumeKey];
                     [[NSUserDefaults standardUserDefaults] synchronize];
                     
                     dispatch_async(dispatch_get_main_queue(),
                     ^{
                         [self volumeDidChangeToLevel: volLevel];
                     });
                 }
            }
        });
    }
    
    @end
    

    If this seems to be an approach you’d like, you might want to consider setting up an object with a delegate callback or a block or something.

    Caveat

    This solution requires a single background thread to watch for changes constantly. It should be pretty low-key, because it’s such a simple check, but it bears mentioning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if I can find a list of where the line break
Does anyone know where I can find a tutorial on how to use GStreamer
Does anyone know if I can create an HTML Form to search the DHL
Does anyone know of any existing packages or libraries that can be used to
Does anyone know where online copies of the old The Perl Journal articles can
Does anyone know how I can, in platform-independent C++ code prevent an object from
Does anyone know if it's possible to display items on a calendar view (on
does anyone know how i can get the id of any element when the
Does anyone know how I can implement a single Touch Event. A simple, one
Does anyone know if I can change a m3u8 file dynamically during runtime of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.