[MAC] XBMC won't give up focus to third party apps called within XBMC
#1
I have setup a program launcher to call Hulu Desktop which is tied to a button on the home screen. What I am running into is the issue where after a few times calling Hulu Desktop, with program lanucher, XBMC will trap the Apple Remote buttons. This gives the effect as if Hulu Desktop does not respond to the Apple Remote buttons.

I have verified this by turning off full screen mode on Hulu Desktop (via the menu at the top left) and I can see XBMC processing the Apple Remote buttons. It even gets worse after continuous use where I can see the OS volume control operating (volume goes up when pressing +, volume goes down when pressing -) while tranversing the XBMC home screen buttons. When this happens I have to go into Settings -> SYSTEM -> Input Devices -> Apple Remote, Disable and then Standard.

Is this an issue with XBMC where it won't give up window focus? I searched for a bug report on this but could not find anything.

I know that there is a XBMC Hulu plugin and I have played around with it. I perfer to use Hulu Desktop.

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 tried an alternate idea where I created a shell script that would kill XBMC, start Hulu Desktop and when Hulu Desktop exited restart XBMC. I ran into two problems with this. First, when I restarted XBMC after Hulu Desktop exited, I lost the use if the Apple remote operation in XBMC. The other problem I ran into was that after several executions of the script I lost use of the Apple remote even for Hulu Desktop. The only way I could correct his was to exit XBMC and kill off XBMCHelper. This behavior is the same no matter if I use the Confluence or Transparency skin.

This is the script I was using:
Code:
#!/bin/bash

ps aux | grep -i `whoami` | grep -v grep | grep XBMC | grep -i MacOS/XBMC | awk '{print $2}' | xargs kill -9

sleep 2

"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"
/Applications/XBMC.app/Contents/MacOS/XBMC --standalone &

I even tried killing off XBMCHelper before calling Hulu Desktop:
Code:
#!/bin/bash

ps aux | grep -i `whoami` | grep -v grep | grep XBMC | grep -i MacOS/XBMC     | awk '{print $2}' | xargs kill -9
ps aux | grep -i `whoami` | grep -v grep | grep XBMC | grep -i osx/XBMCHelper | awk '{print $2}' | xargs kill -9

sleep 2

"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"
/Applications/XBMC.app/Contents/MacOS/XBMC --standalone &

Has anybody managed to get something like this to work continuously? Maybe one of the developers could add there wisdom to this situation.
Reply
#3
I was doing some research and it seems XBMCHelper is the program which handles the IR processing. So what occurred to me was if I killed off the XBMCHelper and then restarted it this might solve the problem which it does.

Unfortunately, this created a new problem. If I have "Allow start of XBMC using remote" enabled and I exit XBMC, when I restart XBMC with the apple remote, XBMC will restart but I can't use the remote any longer. I have to manually kill XBMCHelper, exit XBMC and then manually restart XBMC before I can use the Apple remote again.

jmarshall or davilla thoughts on this issue?

Here is the script:
Code:
#!/bin/sh

ps aux | grep -i `whoami` | grep -v grep | grep XBMCHelper | grep -i osx/XBMCHelper | awk '{print $2}' | xargs kill -9

sleep 0.5

"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"
/Applications/XBMC.app/Contents/Resources/XBMC/tools/osx/XBMCHelper -x &
Reply
#4
Okay, after thinking about the problem a bit more I decided to take a bit of a different approach to finding a work around. What I ended up doing is breaking the solution into two parts, a portion that runs in the background and a portion that runs in the forground.

After a lot of testing I found out that I could not restart the XBMCHelper as part of the XBMC execution. If I restarted the XBMCHelper outside of XBMC I was able to solve the issue of getting XBMC to respond to the Apple remote after Hulu exited. This meant I had to created an independent background task outside of XBMC that I could control within XBMC.

The foreground task was responsible for killing the XBMCHelper, starting Hulu and then restarting XBMCHelper again.

Foreground StartHulu.sh called from the XBMC program launcher:
Code:
#!/bin/bash

#
# Function to retrieve the user level process ID.
#
GetUserProcID()
{
    procname="$1"

    ps -a -U `whoami` | grep "$procname" | grep -v grep |
    while read ProcessInfo
    do
        echo "$ProcessInfo" | cut -d' ' -f1
        break
    done
}

#
# Get the process ID for the StartXBMCHelper background process.
#
StartXBMCHelper_pid=`GetUserProcID StartXBMCHelper.sh`

#
# Kill off the XBMCHelper process so that Hulu Desktop can have focus to process IR commands.
#
kill -9 `GetUserProcID "osx/XBMCHelper"`

#
# Start Hulu Desktop running.  Wait for it to exit.
#
"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"

#
# Tell the StartXBMCHelper background process to restart XBMCHelper.
#
kill -CONT $StartXBMCHelper_pid

Background StartXBMCHelper.sh called from the user .profile:
Code:
#!/bin/bash

#
# Function to retrieve the user level process ID.
#
GetUserProcID()
{
    procname="$1"

    ps -a -U `whoami` | grep "$procname" | grep -v grep |
    while read ProcessInfo
    do
        echo "$ProcessInfo" | cut -d' ' -f1
        break
    done
}

#
# Get the process ID for this background process.
#
scriptname=`basename "$0"`
RunningScript_pid=`GetUserProcID $scriptname`

#
# Get the process ID for this file.
#
pid=$$

#
# Only start one background instance of StartXBMCHelper
#
if [ "$RunningScript_pid" = "$pid" ]
then
    #
    # Continue to run, wakeup to restart XBMCHelper.
    #
    while [ 1 ]
    do
        #
        # Go to sleep.  Wait for the wakeup.
        #
        kill -STOP $pid

        #
        # Restart XBMCHelper.  Detach XBMCHelper so that its parent is not this process.
        #
        ( ( /Applications/XBMC.app/Contents/Resources/XBMC/tools/osx/XBMCHelper -x & ) &
    done
fi

Add to the user .profile:
Code:
"${HOME}/Library/Application Support/XBMC/scripts/StartXBMCHelper.sh" &


Keep in mind that I consider this to be a work around until the issue is actually fixed in XBMC. I create this ticket for the issue.

Update: I have modified the StartXBMCHelper.sh script so that it checks if it is already running, this prevents multiple copies from being executed. Also, according to ticket 11238 this solution will need to be done as the design of XBMCHelper is not designed for releasing focus.

Update 2: I have modified StartXBMCHelper.sh script so that it restarts XBMCHelper so that it is detached from the StartXBMCHelper.sh script running in the background. What I found is when I kill XBMCHelper in the foreground and restart it in the background, when XBMC exits XBMCHelper is left as a zombie process. This creates the issue where XBMC thinks XBMCHelper is running and will not start it again.
Reply
#5
As it turns out, .profile is only executed when a terminal is started which does not work so well for the intended use of the StartXBMCHelper.sh script. What needs to happen is the StartXBMCHelper.sh script get executed when the user logins. So to do this I created an apple script. Open the apple script editor and enter the following:
Code:
do shell script "${HOME}/Library/Application\\ Support/XBMC/scripts/StartXBMCHelper.sh >/dev/null 2>&1 &"

Next click on File->Save As... Select Application for "File Format:" and name it StartXBMCHelper in the directory where the StartXBMCHelper.sh script resides. Exit the apple script editor. Open Accounts in System Preferences. Drag the StartXBMCHelper app to the Login Items. Now logout and log back in. Execute XBMC as usual.

Update: I have simplified the apple script so that it fires off the shell script and then exits.
Reply
#6
Been playing around a little bit more. I have managed to simplify the scripts down to one script, no need for the background script or the apple script. What I ended up with is this:

StartHulu.sh:
Code:
#!/bin/bash

#
# Function to retrieve the user level process ID.
#
GetUserProcID()
{
    procname="$1"

    ps -a -U `whoami` | grep "$procname" | grep -v grep |
    while read ProcessInfo
    do
        echo "$ProcessInfo" | cut -d' ' -f1
        break
    done
}

#
# Kill off the XBMCHelper process so that Hulu Desktop can have focus to process IR commands.
#
kill -9 `GetUserProcID "osx/XBMCHelper"`

#
# Start Hulu Desktop running.  Wait for it to exit.
#
"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"

#
# Restart XBMCHelper.  Detach XBMCHelper so that its parent is not this script.
#
( ( /Applications/XBMC.app/Contents/Resources/XBMC/tools/osx/XBMCHelper -x & ) & )

I simply point the program launcher to the above script and now I am able to execute Hulu Desktop, exit Hulu Desktop and return to XBMC and have the remote respond.
Reply
#7
Thanks for the script. It's almost perfect but I'm running into problems if I exit XBMC for anything other than Hulu. Again thanks for all the hard work on this it's still very useful for me but I occasionally will drop out of XBMC to open a web browser or some other program and afterwords my remote no longer works.

Mac Mini running 10.5 Leopard with XBMC 10.1 dmg install
Allow start of XBMC using the remote: On

To reproduce:
I boot the machine and launch XBMC with the menu button
I exit XBMC
I relaunch XBMC with the menu button

Result: Everything is still working fine. I can do this repeatedly.

I launch StartHulu.sh via Launcher inside XBMC
I exit Hulu
I exit XBMC
I relaunch XBMC with the menu button

XBMC is no longer responsive to remote commands. A reboot is required to fix the issue.

xbmc.log: http://pastebin.com/PS4nBFC4
Reply
#8
wardjame Wrote:I launch StartHulu.sh via Launcher inside XBMC
I exit Hulu
I exit XBMC
I relaunch XBMC with the menu button

XBMC is no longer responsive to remote commands. A reboot is required to fix the issue.

Hi wardjame,

I was also able to reproduce the problem. I have no idea why the remote stops working after exiting and re-start XBMC from the remote. I am not sure if XBMC Helper was designed to be killed off and restarted while XBMC is running. Maybe one of the developers can chime in on this.

Instead of rebooting the Mac-Mini do this when the remote stops working:

1) Open the terminal command.
2) At the terminal prompt enter: ps -a -U `whoami` | grep "osx/XBMCHelper" | grep -v grep
3) Observe the second number displayed on the far left, this is the UID number. You will use that the number in the next step.
4) At the terminal prompt enter: kill -9 <UID # observed in step 3>
5) Manually restart XBMC.
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
#9
I wanted to revive this thread because I came up with a way to recover the use of the Apple remote when you exit and then restart XBMC after using Hulu Desktop.

What I came up with was a script that runs at the user login and monitors when XBMC starts running and after it has exited it will restart the XBMCHelper if "Allow start of XBMC using the remote" as been enabled.

Create a UNIX shell script called Monitor_XBMC.sh:
Code:
#!/bin/bash

# Algorithm:
#
# Indicate need to check for XBMC running
# Indicate no need to restart XBMCHelper
#
# Loop forever
#     if need to check for XBMC running
#     then
#         if XBMC is running
#         then
#             Indicate need to restart XBMCHelper
#             Indicate no need to check for XBMC running
#         end if
#     end if
#
#     if need to restart XBMCHelper
#     then
#         if XBMC is not running
#         then
#             Kill XBMCHelper process
#             Start XBMCHelper process
#
#             Indicate no need to restart XBMCHelper
#             Indicate need to check for XBMC running
#         end if
#     end if
#
#     Go to sleep for 1 second
# end loop
#

# Which XBMC version is being used
XBMC_VER=11

# Different locations for XBMCHelper
XBMC_10_XBMCHelper="osx/XBMCHelper"
XBMC_11_XBMCHelper="runtime/XBMCHelper"

# How to identify if XBMC and XBMCHelper processes are running.
XBMC="MacOS/XBMC"
XBMCHelper=XBMC_${XBMC_VER}_XBMCHelper
XBMCHelper=${!XBMCHelper}

# Different sleep values.
Sleep_Timer=1

TRUE=0
FALSE=1

#
# Function to retrieve the path for a running process.
#
Get_Proc_Path()
{
    Proc_Name="$1"

    # Get the process list for the user.
    ps -a -U `whoami` | grep "${Proc_Name}" | grep -v grep |

    # Strip off the path of the process.
    while read Process_Info
    do
        echo "${Process_Info}" | awk '{ print $4 }'
        break
    done
}

#
# Function to determine if the process is running.
#
Is_Running()
{
    # Get the Path where the process is executing.
    Proc_Name="$1"
    Proc_Path="`Get_Proc_Path ${Proc_Name}`"
    Proc_Is_Running=${FALSE}

    # If there is no path then the process is not running.
    if [ -n "${Proc_Path}" ]
    then
        Proc_Is_Running=${TRUE}
    fi

    return ${Proc_Is_Running}
}

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# Start by checking if XBMC is running.
Check_For_XBMC_Running=true
Restart_XBMCHelper=false

# Continue to run until stopped.
while (true)
do
    # Determine if XBMC is running?
    if ($Check_For_XBMC_Running)
    then
        # Is XBMC running?
        if (`Is_Running ${XBMC}`)
        then
            # Get the path of where XBMCHelper is executing.
            XBMCHelper_Path="`Get_Proc_Path ${XBMCHelper}`"

            # Don't need to check if XBMC is running.
            Check_For_XBMC_Running=false

            # Indicate that XBMCHelper needs to be restarted.
            Restart_XBMCHelper=true
        fi
    fi

    # Time to restart XBMCHelper?
    if ($Restart_XBMCHelper)
    then
        # Wait for XBMC to exit.
        if (! `Is_Running ${XBMC}`)
        then
            # Only need to restart XBMCHelper if the following is enabled:
            #    'Allow start of XBMC using the remote'
            if (`Is_Running ${XBMCHelper}`)
            then
                # Kill the current XBMCHelper process.
                killall -9 XBMCHelper

                # Restart the XBMCHelper process.
                ( ( ${XBMCHelper_Path} -x & ) & )
            fi

            # Start all over again, by determing if XBMC is running.
            Check_For_XBMC_Running=true

            # Indicate that XBMCHelper does not need to be restarted.
            Restart_XBMCHelper=false
        fi
    fi

    # Sleep for a period of time.
    sleep $Sleep_Timer
done

I wrote Monitor_XBMC.sh script so that it could work for XBMC 10 and XBMC 11. The location where XBMCHelper resides is different in XBMC 10 and XBMC 11. Set the following line in the shell script (to either 10 or 11) depending on what version of XBMC you are using:
Code:
# Which XBMC version is being used
XBMC_VER=11

Open terminal and "cd" to where the Monitor_XBMC.sh resides. Execute the following from command:
Code:
chmod 755 Monitor_XBMC.sh

Open the AppleScript editor and enter the following:
Code:
do shell script "cd ~; \"Library/Application Support/XBMC/scripts/Monitor_XBMC.sh\""

I place all my scripts pretaining to XBMC in ~/Library/Application Support/XBMC/scripts. This is where I placed the Monitor_XBMC.sh and Monitor_XBMC AppleScript. If you place Monitor_XBMC.sh in a different location make sure to change the Monitor_XBMC AppleScript to reflect that location.

From the AppleScript editor select File -> Save As... Enter Monitor_XBMC as the Save As name and select Application as the File Format. This now creates a application that can be run stand alone.

Open the folder where you created the Monitor_XBMC AppleScript application select Monitor_XBMC, Control-mouse-click and then select "Show Package Contents". Navigate to the Contents folder and open the info.plist with a text editor. Tranverse to the end of the info.plist file and add the following lines just before the last </dict> line:
Code:
    <key>NSUIElement</key>
    <string>1</string>

Save the info.plist. What you have just now is modified the Monitor_XBMC application so that when you run it it will be hidden from the dock.

The last thing that needs to be done is open System Preferences and add the AppleScript Monitor_XBMC application to login items. The Monitor_XBMC.sh script will be automatically run when you login.

Let me know if there are any issues with using the script.
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
#10
My setup is simple: Safari is lauched via Advanced Launcher opens up. Even if the script is running XBMC won't quit. Can you help?
Reply
#11
RodriguezF,

The StartHulu script I wrote simply exits XBMCHelper when Hulu Desktop is executed. It does not exit XBMC.

You can take my StartHulu.sh script and modify it so that it kills off XBMC and XBMCHelper and the executes /Applications/Safari.app/Contents/MacOS/Safari. It will also have to restart XBMC when Safari exits.
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
I have simplifed the StartHulu.sh script further and made it XBMC version independent. This script will work for XBMC 10.1 and 11 without modifications:
Code:
#!/bin/bash

# The base path of where XBMC resides.
XBMC_APP="/Applications/XBMC.app"

#
# Function to determine the path for an executable.
#
WhereIs()
{
    Exe_Name="$1"

    find "${XBMC_APP}" -type f -name "${Exe_Name}" -print
}

# Get the paths where XBMCHelper reside.
XBMCHelper=`WhereIs XBMCHelper`

#
# Kill off the XBMCHelper process so that Hulu Desktop can have focus to process IR commands.
#
killall -9 XBMCHelper

#
# Start Hulu Desktop running.  Wait for it to exit.
#
"/Applications/Hulu Desktop.app/Contents/MacOS/Hulu Desktop"

#
# Restart XBMCHelper.  Detach XBMCHelper so that its parent is not this script.
#
( ( ${XBMCHelper} -x & ) & )
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
#13
One of the things that I have changed with the XBMC_Monitor AppleScript is that it will execute the Monitor_XBMC.sh script in the background and then exit. The previous version of the AppleScript will wait for a reply back from the Montior_XBMC.sh shell script.

This is version 2 of the Monitor_XBMC AppleScript:
Code:
do shell script "cd ~; \"Library/Application Support/XBMC/scripts/Monitor_XBMC.sh\" >/dev/null 2>&1 &"

The changes that I have made to version 2 of the Monitor_XBMC.sh shell script is that I have simplified it and it will now work for XBMC 10.1 and 11 without modifications:
Code:
#!/bin/bash

# Algorithm:
#
# Indicate need to check for XBMC running
# Indicate no need to restart XBMCHelper
#
# Loop forever
#     if need to check for XBMC running
#     then
#         if XBMC is running
#         then
#             Indicate need to restart XBMCHelper
#             Indicate no need to check for XBMC running
#         end if
#     end if
#
#     if need to restart XBMCHelper
#     then
#         if XBMC is not running
#         then
#             Kill XBMCHelper process
#             Start XBMCHelper process
#
#             Indicate no need to restart XBMCHelper
#             Indicate need to check for XBMC running
#         end if
#     end if
#
#     Go to sleep for 1 second
# end loop
#

# The base path of where XBMC resides.
XBMC_APP="/Applications/XBMC.app"

# Sleep Timer value.
Sleep_Timer=1

TRUE=0
FALSE=1

#
# Function to determine the path for an executable.
#
WhereIs()
{
    Exe_Name="$1"

    find "${XBMC_APP}" -type f -name "${Exe_Name}" -print
}

# Get the paths where XBMC and XBMCHelper reside.
XBMC=`WhereIs XBMC`
XBMCHelper=`WhereIs XBMCHelper`

# Get the user name of who is running this script.
USER=`whoami`

#
# Function to determine if the process is running.
#
Is_Running()
{
    # Get the Path where the process is executing.
    Proc_Name="$1"
    Running=${FALSE}

    # Get the process list for the user and return the process entry if it is running.
    Proc_Entry=`ps -a -U ${USER} | grep "${Proc_Name}" | grep -v grep`

    # If there is no path then the process is not running.
    if [ -n "${Proc_Entry}" ]
    then
        Running=${TRUE}
    fi

    return ${Running}
}

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# Start by checking if XBMC is running.
Check_For_XBMC_Running=true
Restart_XBMCHelper=false

# Continue to run until stopped.
while (true)
do
    # Determine if XBMC is running?
    if ($Check_For_XBMC_Running)
    then
        # Is XBMC running?
        if (`Is_Running "${XBMC}"`)
        then
            # Don't need to check if XBMC is running.
            Check_For_XBMC_Running=false

            # Indicate that XBMCHelper needs to be restarted.
            Restart_XBMCHelper=true
        fi
    fi

    # Time to restart XBMCHelper?
    if ($Restart_XBMCHelper)
    then
        # Wait for XBMC to exit.
        if (! `Is_Running "${XBMC}"`)
        then
            # Only need to restart XBMCHelper if the following is enabled:
            #    'Allow start of XBMC using the remote'
            if (`Is_Running "${XBMCHelper}"`)
            then
                # Kill the current XBMCHelper process.
                killall -9 XBMCHelper

                # Restart the XBMCHelper process.
                ( ( "${XBMCHelper}" -x & ) & )
            fi

            # Start all over again, by determing if XBMC is running.
            Check_For_XBMC_Running=true

            # Indicate that XBMCHelper does not need to be restarted.
            Restart_XBMCHelper=false
        fi
    fi

    # Sleep for a period of time.
    sleep $Sleep_Timer
done
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

Logout Mark Read Team Forum Stats Members Help
[MAC] XBMC won't give up focus to third party apps called within XBMC0