How do I control the system volume on OS X with a keyboard without media controls?

59,373

Solution 1

You can buy the pro version of Sizzling Keys. It is a preference pane that allows you to define a custom keyboard shortcut for modifying system volume, among lots of other things.


Alternatively, you can modify system volume using AppleScript.

Open up AppleScript Editor and enter

set volume output volume 100

Volume is on a scale of 0 to 100. You can either set an absolute value (e.g. 100 for full volume), or create scripts that increase/decrease, such as the following:

set vol to output volume of (get volume settings)
if vol > 90 then # 100 max
    set volume output volume 100
else
    set volume output volume (vol + 10)
end if

For Volume Down:

set vol to output volume of (get volume settings)
if vol < 10 then # 0 is min
    set volume output volume 0
else
    set volume output volume (vol - 10)
end if

If you'd like to replicate the feedback sound that normally occurs when you change volume, you could add the following to the script:

    do shell script "afplay /System/Library/Sounds/Pop.aiff"

You can save scripts as these as applications, or integrate them into the Services menu using Automator as an input-less service. You can define keyboard shortcuts for services in System Preferences » Keyboard » Keyboard Shortcuts » Services

Solution 2

Karabiner (formerly KeyRemap4MacBook) can remap function keys to control volume, and has been working seamlessly for me so far. In the control panel, search for "F9 to mute" etc.

Solution 3

I've packaged up a set of AppleScript services and instructions that let you control system & iTunes volume, as well as play/pause & next/prev on any keyboard in Lion.

http://gskinner.com/blog/archives/2011/10/media-keys-in-osx-for-any-keyboard.html

Solution 4

Old thread but the way I solved it is via a single line applescript based on other answers

Increase volume by 10%

osascript -e 'set volume output volume ((output volume of (get volume settings)) + 10)'

Decrease volume by 10%

osascript -e 'set volume output volume ((output volume of (get volume settings)) - 10)'

Actually ended up writing a blog post about using it with Alfred app: http://arif.im/system-volume-control-using-alfred/

Solution 5

Here is my complete solution for shortcuts for volume up, down, and mute. I use the Spark application to bind key combinations to these scripts (http://www.macupdate.com/app/mac/14352/spark). The scripts check for the current mute state and handle it, so as to avoid weird problems that can happen if you don't properly control it.

Volume up:

set vol to output muted of (get volume settings)
if (vol = true) then
    set volume without output muted
end if
set vol to output volume of (get volume settings)
if vol > 95 then
    set volume output volume 100
else
    set volume output volume (vol + 5)
end if

do shell script "afplay /System/Library/Sounds/Pop.aiff"

Volume down:

set vol to output muted of (get volume settings)
if (vol = true) then
    error number -128
else
    set vol to output volume of (get volume settings)
    if vol < 5 then # 0 is min
        set volume with output muted
    else
        set volume output volume (vol - 5)
    end if

    do shell script "afplay /System/Library/Sounds/Pop.aiff"

end if

Mute/Unmute:

set vol to output muted of (get volume settings)
if (vol = true) then
    set volume without output muted
else
    set volume with output muted
end if
Share:
59,373

Related videos on Youtube

phbelov
Author by

phbelov

Code in Scala, Ruby, Rails, Python (and Java if necessary). Use Vim, TextMate, IntelliJ, Eclipse and NetBeans (in that order). Very interested in geodata and RDF. Have helped organise BarCampLondon and a few hack days. Use OS X and Debian/Ubuntu (anything with apt), stay well clear of Windows. Twitter: http://twitter.com/tommorris

Updated on September 17, 2022

Comments

  • phbelov
    phbelov over 1 year

    I'm using a PC keyboard on Mac OS. I can use the menubar to control the volume, but are there any keyboard shortcuts I can use to change the system volume?

    Or perhaps a simple script or solution I can install to be able to set the volume using the keyboard.

  • HikeMike
    HikeMike over 13 years
    PC keyboard, as in not usually equipped with an Fn key.
  • Tamara Wijsman
    Tamara Wijsman over 12 years
    Welcome to Super User! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
  • nonagon
    nonagon almost 10 years
    This was perfect. For those who haven't done it before: run Automator, File/New/Service, under Service receives selected choose "no input", on the left next to Variables search for "Run AppleScript" and double-click it, paste one of these scripts below where it says "your script goes here", click green run button to test it, save as "Volume Up" or "Volume Down", System Prefs/Keyboard/Shortcuts, select "Services" on the left, these should show up at the bottom where you can assign keyboard shortcuts. I had to run the services manually from the services menu once before the shortcuts worked.
  • Mohsen Kamalzadeh
    Mohsen Kamalzadeh over 9 years
    Oh I forgot that part. Done :)
  • Tolga Ozses
    Tolga Ozses almost 8 years
    After much trial, I found out that key assignments work outside Finder only if you set Full Keyboard Access to All controls