[MAC] Volume Level Control
#1
Hi,

I am using the Apple remote to control the XBMC menus and play videos. I have noticed that when I turn up the volume using the + and - buttons, on the remote, the volume only seems to control the internal XBMC volume level and not the OS volume level. Is there a way to change the behavior so that changing the volume through the remote will change the OS volume level instead of the XBMC volume level? I have searched the forums but found no answer.

Any help would be appreciated.

OSX Version 10.6.6
Platform 2008 24" 3.06GHz iMac with 4GB RAM
Install Method dmg
SVN Revision 35648
Skin Transparency!
Reply
#2
I don't think there's a way to do it through XBMC, but I use Remote Buddy and have a key on the remote mapped (using remote buddy) to bring up the Remote Buddy menu. You can then do it through there.
Reply
#3
Snowdrift,

I was unsure thanks for confirming it for me. I am working on a possibility that would allow XBMC to control the OS volume level. Unfortunately, I am stuck on the solution until I can figure out why System.Exec is not working from within keymap.xml. I have started a topic on this: http://forum.xbmc.org/showthread.php?tid=92506.
Reply
#4
winestock Wrote:Snowdrift,

I was unsure thats for confirming it for me. I am working on a possibility that would allow XBMC to control thr OS volume level. Unfortunately, I am stuck on the solution until I can figure out why System.Exec is not working from within keymap.xml. I have started a topic on this: http://forum.xbmc.org/showthread.php?tid=92506.

Cool. I will watch that thread with interest. Incidentally, have you tried the command to System.Exec without the quotes?
Reply
#5
Snowdrift,

I have tired calling System.Exec with and without quotes both resulting in the same issue, non-execution of the shell script. I know the keymap.xml is working because when I replace the System.Exec call with VolumeUp the volume level changes for the internal XBMC volume level.
Reply
#6
I did some looking around and found a good work around to allow me to control the OS volume level from my Apple remote. At first I wanted to use the built-in function System.Exec but for some reason I could never get it to work in userdata/keymaps/keymap.xml. I opened a bug report on this.

It was posted, in another thread, that apple scripts could be called via the RunScript command. So for those who are interested here are the changes I made to be able to control the OS volume level using the Apple Remote while XBMC was playing a movie:

userdata/keymaps/keymap.xml:
Code:
<keymap>
  <Home>
    <joystick name="AppleRemote">
      <button id="6"></button>
      <button id="8">ActivateWindow(shutdownmenu)</button>
    </joystick>
  </Home>
  <FullscreenVideo>
    <joystick name="AppleRemote">
      <button id="1">RunScript(../scripts/VolumeUp.applescript)</button>
      <button id="2">RunScript(../scripts/VolumeDown.applescript)</button>
      <button id="3">StepBack</button>
      <button id="4">StepForward</button>
      <button id="5">Pause</button>
      <button id="6">Stop</button>
      <button id="7">OSD</button>
      <button id="8">ShowVideoMenu</button>
      <button id="9">Rewind</button>
      <button id="10">FastForward</button>
      <button id="11">Rewind</button>
    </joystick>
  </FullscreenVideo>
  <VideoMenu>
    <joystick name="AppleRemote">
      <button id="5">Select</button>
      <button id="6">Stop</button>
      <button id="7">OSD</button>
      <button id="8">ShowVideoMenu</button>
    </joystick>
  </VideoMenu>
</keymap>

VolumeUp.applescript:
Code:
-- volume up 10
set current_volume to output volume of (get volume settings)

if current_volume is less than 100 then
    set current_volume to current_volume + 10
end if

set volume output volume current_volume

VolumeDown.applescript:
Code:
-- volume down 10
set current_volume to output volume of (get volume settings)

if current_volume is greater than 0 then
    set current_volume to current_volume - 10
end if

set volume output volume current_volume

A few things to note about the above files. If you noticed I used "../scripts" in keymap.xml. The nice thing about this is if you share the userdata among multiple machines, that have different users, no change is required. I place my scripts in the scripts directory that is at the same level as the keymaps directory. I also changed button ID 8 from FullScreen to ShowVideoMenu as I wanted to be able to easily access the DVD menu without having to go through the OSD menu.

The above work around seems to work really well. You don't lose the ability to change the XBMC volume level, you would now have to go through the OSD menu to change it.

One thing not included in this work around is the ability to show what the OS volume level is changing to. I would love to be able to display the volume level like OS X does with its tranparent window. I will research more and see what I can find. I did open a feature request to have a built-in capability to change the OS volume level in XBMC.
Reply
#7
By the way, name the file keyboard.xml in userdata/keymaps. keymap.xml has been depreciated.

I have made a change to VolumeUp.applescript and VolumeDown.applescript so that they are more percise in how they lower and raise the OS volume level. The changes I made follow the values Apple uses.

VolumeUp.applescript:
Code:
-- List of all volume values.
set VolumeList to ¬
    {0, 6, 13, 19, 25, 32, 37, 43, 49, 56, 64, 69, 74, 82, 88, 94, 100}
set VolumeListLen to count of VolumeList

-- Get the current OS volume level.
set CurrentVolume to output volume of (get volume settings)
set VolumeIndex to 1

-- Determine what the current volume level is so that the volume
-- can be raised.
repeat with VolumeFound in VolumeList
    if VolumeFound ≥ CurrentVolume then
        exit repeat
    end if
    
    -- Did not find the current volume level so look at the next value.    
    set VolumeIndex to VolumeIndex + 1
end repeat

-- Determine what the next lower volume level will be.
if VolumeIndex < VolumeListLen then
    set VolumeIndex to VolumeIndex + 1
end if

set NextVolume to item VolumeIndex of VolumeList

-- Volume Up
set volume output volume NextVolume

VolumeDown.applescript:
Code:
-- List of all volume values.
set VolumeList to ¬
    {0, 6, 13, 19, 25, 32, 37, 43, 49, 56, 64, 69, 74, 82, 88, 94, 100}
set VolumeListLen to count of VolumeList

-- Get the current OS volume level.
set CurrentVolume to output volume of (get volume settings)
set VolumeIndex to 1

-- Determine what the current volume level is so that the volume
-- can be lowered.
repeat with VolumeFound in VolumeList
    if VolumeFound ≥ CurrentVolume then
        exit repeat
    end if
    
    -- Did not find the current volume level so look at the next value.    
    set VolumeIndex to VolumeIndex + 1
end repeat

-- Determine what the next lower volume level will be.
if VolumeIndex > 1 then
    set VolumeIndex to VolumeIndex - 1
end if

set PrevVolume to item VolumeIndex of VolumeList

-- Volume down.
set volume output volume PrevVolume
Reply
#8
Had a bit of a struggle getting this working, but here's what I did:

1) put my scripts in /Users/Shared/scripts (I was iffy on whether or not the relative dir was working...might not have been the problem)

2) updated the array of volume numbers:

{0, 6, 13, 19, 25, 32, 37, 43, 50, 56, 64, 70, 74, 82, 88, 94, 100}

The down volume was working intermittently, and using the applescript editor, I tracked it down to a mismatch between 49/50, 69/70.

Works great now!
Reply
#9
(2011-11-03, 01:26)jhkrischel Wrote: Had a bit of a struggle getting this working, but here's what I did:

1) put my scripts in /Users/Shared/scripts (I was iffy on whether or not the relative dir was working...might not have been the problem)

2) updated the array of volume numbers:

{0, 6, 13, 19, 25, 32, 37, 43, 50, 56, 64, 70, 74, 82, 88, 94, 100}

The down volume was working intermittently, and using the applescript editor, I tracked it down to a mismatch between 49/50, 69/70.

Works great now!

I did all of this and only the VolumeUp works... volume down does nothing but the volume slider doesn't pop up either... I'm using the first generation of apple remotes i don't know if that matters.

Thanks,
Reply
#10
I know this is old but I'm trying to get this to work on my imac to control the volume. I have setup the applescripts and they work when i run them within the applescript editor. I have the xml file created and placed in the /userdata/keymaps/ and i have the file named keyboard.xml per the instructions. The + and - still don't adjust the OS volume in XBMC when a video is playing? Has something changed since this was posted?! It's driving me crazy not being able to get it to work. Thanks!
Reply
#11
(2014-04-24, 20:41)Ecklund Wrote: I know this is old but I'm trying to get this to work on my imac to control the volume. I have setup the applescripts and they work when i run them within the applescript editor. I have the xml file created and placed in the /userdata/keymaps/ and i have the file named keyboard.xml per the instructions. The + and - still don't adjust the OS volume in XBMC when a video is playing? Has something changed since this was posted?! It's driving me crazy not being able to get it to work. Thanks!

Hi Ecklund,

I have since changed how I am doing the OS X system volume change in XBMC. Try this and see how it works for you.

XBMC/userdata/keymaps/keyboard.xml:
Code:
<keymap>
    <Home>
        <joystick name="AppleRemote">
            <!-- hold menu  -->     <button id="8">ActivateWindow(shutdownmenu)</button>
        </joystick>
    </Home>
    <FullscreenVideo>
        <joystick name="AppleRemote">
            <!-- plus       -->     <button id="1">RunScript(VolumeUp.py)</button>
            <!-- minus      -->     <button id="2">RunScript(VolumeDown.py)</button>
            <!-- left       -->     <button id="3">BigStepBack</button>
            <!-- right      -->     <button id="4">BigStepForward</button>
            <!-- play       -->     <button id="5">Pause</button>
            <!-- menu       -->     <button id="6">Stop</button>
            <!-- hold play  -->     <button id="7">OSD</button>
            <!-- hold menu  -->     <button id="8">ShowVideoMenu</button>
            <!-- hold left  -->     <button id="9">Rewind</button>
            <!-- hold right -->     <button id="10">FastForward</button>
            <!-- hold left  -->     <button id="11">Rewind</button>
        </joystick>
    </FullscreenVideo>
    <VideoMenu>
        <joystick name="AppleRemote">
            <!-- play      -->      <button id="5">Select</button>
            <!-- menu      -->      <button id="6">Stop</button>
            <!-- hold play -->      <button id="7">OSD</button>
            <!-- hold menu -->      <button id="8">ShowVideoMenu</button>
        </joystick>
    </VideoMenu>
    <MyVideoLibrary>
        <joystick name="AppleRemote">
            <!-- hold play -->      <button id="7">Info</button>
            <!-- hold menu -->      <button id="8">Stop</button>
        </joystick>
    </MyVideoLibrary>
</keymap>

VolumeUp.py:
Code:
import sys
import os

whichOS = sys.platform

if whichOS == 'darwin':
    whichScript = "\"" + os.path.splitext(__file__)[0] + ".applescript\""

    os.system("/usr/bin/osascript " + whichScript)

VolumeDown.py:
Code:
import sys
import os

whichOS = sys.platform

if whichOS == 'darwin':
    whichScript = "\"" + os.path.splitext(__file__)[0] + ".applescript\""

    os.system("/usr/bin/osascript " + whichScript)

VolumeUp.applescript:
Code:
-- Get the current OS volume level.
set CurrentVolume to output volume of (get volume settings)

-- Determine what the absolute current volume level is so that the volume
-- can be raised.
set AbsVolume to ((CurrentVolume + 5) Div 10) * 10

if AbsVolume < 100
    -- Determine what the next lower volume level will be.
    set AbsVolume to (AbsVolume + 10)

    -- Volume up.
    set volume output volume (AbsVolume)
end if

VolumeDown.applescript:
Code:
-- Get the current OS volume level.
set CurrentVolume to output volume of (get volume settings)

-- Determine what the absolute current volume level is so that the volume
-- can be lowered.
set AbsVolume to ((CurrentVolume + 5) Div 10) * 10

if AbsVolume > 0
    -- Determine what the next lower volume level will be.
    set AbsVolume to (AbsVolume - 10)

    -- Volume down.
    set volume output volume (AbsVolume)
end if
Kodi 17, Transparency Skin
PogoPlug v4 running Arm Linux 4.4.63 as MySQL (mariadb) server.
Mac OS 10.12.5
2015 27" iMac 3.3 GHz Quad, 16GB RAM, 1TB SSD
2015 13" Macbook Pro, 8GB RAM, 256GB SSD
AppleTV 4 TV OS 10
Reply
#12
Here is a simple Volume-up keymap for Apple Remote HOLD CENTRE that I used successfully before switching to fixed max volume (due to HDMI output) .. took me ages to get to work - syntax on runscript should be exactly as below.

(see Winestock for his excellent Applescript - I used a modified earlier version to quickly jump vol in larger increments )

keyboard.xml

<keymap>
<FullscreenVideo>
<joystick name="AppleRemote">
<button id="1">VolumeUp</button>
<button id="2">VolumeDown</button>
<button id="3">StepBack</button>
<button id="4">StepForward</button>
<button id="5">Pause</button>
<button id="6">Stop</button>
<button id="7">runscript(/Users/chris/Library/Application Support/XBMC/scripts/VolumeUp.applescript)</button>
<button id="8">OSD</button>
<button id="9">Rewind</button>
<button id="10">FastForward</button>
</joystick>
</FullscreenVideo>
</keymap>
Reply
#13
Thanks for your assistance! I'm still unable to get it to work. Do I have to have the py files and the applescript files in the keymap directory or do they still go into a scripts directory? Do i need to customize anything in those py files to my filenames or anything? I'm very unfamiliar with scripting, etc. Currently I have the xml, py, and applescript files all together in the keymap directory but I tried them in a sep directory first. Only thing that happens in XBMC when i attempt to adjust volume is it just changes the in app volume still. Does it matter that I am using an older white apple remote instead of the newer aluminum one?

Thanks again for all of your help!
Reply
#14
Aren't you guys experiencing small freezes when playing a video and executing an applescript? Every time i press the volume keys, the video is stopped while the script is being executed.

I'm using this applescript to control the volume of my Marantz-AVR:
Code:
set telnet to "(echo MVUP; sleep 0.1) | telnet 192.168.0.74 23 > /dev/null 2>&1 &"

do shell script telnet
delay 0.1
do shell script telnet
delay 0.1
do shell script telnet
delay 0.1
do shell script telnet


Also - why are you using keyboard.xml instead of joystick.AppleRemote.xml?
Reply
#15
(2014-04-30, 13:00)Ecklund Wrote: Thanks for your assistance! I'm still unable to get it to work. Do I have to have the py files and the applescript files in the keymap directory or do they still go into a scripts directory? Do i need to customize anything in those py files to my filenames or anything? I'm very unfamiliar with scripting, etc. Currently I have the xml, py, and applescript files all together in the keymap directory but I tried them in a sep directory first. Only thing that happens in XBMC when i attempt to adjust volume is it just changes the in app volume still. Does it matter that I am using an older white apple remote instead of the newer aluminum one?

Thanks again for all of your help!

Put the applescript in the script directory

/Users/YOURUSER/Library/Application Support/XBMC/scripts/

My example and syntax for keyboard.xml launching the script does work

You could check the permissions give you execute and read on the script - did you create it with the same user - should be fine if so
Reply

Logout Mark Read Team Forum Stats Members Help
[MAC] Volume Level Control0