[MOD] Program Launcher Hack
#1
Hey guys, new to the forums, been using XBMC for a little bit. Hope this is the right place to post this, I don't know if it really counts as a 'mod' or more of a hack. Anyways, I'd been looking for something that could launch an external program from XBMC for a while, and while the program launcher is available it wasn't quite what I wanted, I just wanted to be able to launch 1 specific program from the main menu.

This is a simple mod, you only have to script 1 python script and edit 1 xml file.

In my example below I'm using a python script to launch a program (which in turn launches several other programs and returns when they close)

As you can see all that's really necessary is the python launcher and the main menu to call the python.

----------

Image

Ok here's a quick writeup on how to mod your XBMC to launch HyperSpin directly from the Home menu. This WILL disable your 'my programs' submenu entirely. Though I'm sure you could mod it differently I wanted this to replace the 'My Programs / My Games' on the Aeon Stark skin because all the other settings menus remain in tact, meaning you can still setup backdrops without making any additional mods.

This mod consists of 4 basic things

1) Home Menu edit
2) Python script
3) AHK Hyperspin launcher
4) AHK XBMC launcher

First I will explain a little bit about why I scripted things the way I did.

The primary reason was to minimize cpu/memory use.

The second was that I have read that Hyperspin / XBMC don't like to play nice together and that there can be some issues when trying to run both programs simultaneously.

The final reason is to make it easily customizable for each users needs - if you want to launch / close extra programs, you can.

The following is a basic flowchart of how this wrapper works:

Quote:Run XBMC
- Click 'HyperSpin'
- Run Python Script
- Run Hyperspin Launcher
- Close Python Script
- Close XBMC
- Run HyperSpin
- Run other programs if desired
- Close HyperSpin Launcher
- Exit HyperSpin
- Run XBMC Launcher
- Close other programs if opened previously
- Run XBMC
- Exit XBMC Launcher
- Exit XBMC

--------------------
PART 1: Python Script (launcher.py)

The Following is assuming that you have XBMC installed in it's default location of

C:\Program Files\XBMC\

From here out referred to as 'XBMC root'

Quote:import os, subprocess

subprocess.Popen(["c:\Program Files\XBMC\spinner.exe"], shell=False)

Copy the above code to notepad and save it in the XBMC root as launcher.py If necessary edit the path to your XBMC root.

---------------
PART 2: HyperSpin AHK Script (spinner.ahk)

This script also goes in the XBMC root directory.

Quote:#SingleInstance force

;----------SET PATHS----------;
XBMC = "C:\Program Files\XBMC\XBMC.exe"
HyperSpin= "E:\HyperSpin\HyperSpin.exe"
;-----------------------------;


blockinput, on
SetTitleMatchMode, 2
Gui, Color, 000000
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
process, close, xbmc.exe
run, %HyperSpin%,, UseErrorLevel
if ErrorLevel
{
run, %XBMC% -fs -p,, UseErrorLevel
if Errorlevel = ERROR
{
gui, destroy
blockinput, off
msgbox, 0, ERROR, neither %XBMC% or %HyperSpin% was found - Make sure you have correct paths, 4
ExitApp
}
WinWait, XBMC, , 5
IfWinNotActive, XBMC, , WinActivate, XBMC,
WinWaitActive, XBMC, , 5
if ErrorLevel
{
gui, destroy
blockinput, off
ExitApp
}
sleep, 5000
gui, destroy
blockinput, off
ExitApp
}
WinWait, HyperSpin, , 3
IfWinNotActive, HyperSpin, , WinActivate, HyperSpin,
WinWaitActive, HyperSpin
sleep, 3000
gui, destroy
blockinput, off
ExitAPP

At the very beginning of the script you will see an area to set paths to your programs. adjust them accordingly.

The numbers in green are the timeouts that the script will run while waiting for the respective program to 1)launch 2)gain focus. You can lengthen / shorten these according to your system specs. The defaults seem to work well.

If the script cannot find HyperSpin.exe it will relaunch XBMC.exe and exit the script. IF it cannot find XBMC.exe to relaunch - it will throw an error asking if your paths are correct. Check, and recompile.

compile this script as spinner.exe (which the python script was looking for)

* If you want to run another program I would add the 'run' command right before the final 'sleep, 3000' and before the 'gui, destroy' lines.

---------------
PART 3: XBMC Launcher AHK Script (Xlauncher.ahk)

This script also goes in the root xbmc directory

Quote:#SingleInstance force

;----------SET PATHS----------;
XBMC = "C:\Program Files\XBMC\XBMC.exe"
;-----------------------------;


blockinput, on
SetTitleMatchMode, 2
Gui, Color, 000000
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
run, %XBMC% -fs -p,, UseErrorLevel
if ErrorLevel
{
gui, destroy
blockinput, off
msgbox, 0, ERROR, %XBMC% was not found - Make sure you have correct paths, 4
ExitApp
}
WinWait, XBMC, , 5
IfWinNotActive, XBMC, , WinActivate, XBMC,
WinWaitActive, XBMC, , 5
if ErrorLevel
{

sleep, 5000
gui, destroy
blockinput, off
ExitApp
}
sleep, 5000
gui, destroy
blockinput, off
ExitAPP

again, edit your path to XBMC - if it isn't the default - and adjust the timeouts in green if necessary.

If you have any programs you want to close (Xpadder, Ledblinky...)

use 'process, close,' right before the 'run, %xbmc%' line.

Compile and save as Xlauncher.exe

Open HyperHQ and set this program as the program you want to run on exit.

*it technically isn't necessary for this to be in the XBMC root - just makes it easier to find.

----------

PART 4: SKINS

++++++++++
AEON STARK

find the following file

'Includes_mainmenu.xml'

by default it will be under

\skin\Aeon\720p\

from your XBMC root directory.

Open it in your favourite text editor and find the following:

Quote: <item id="2">
<label>31011</label>
<onclick>XBMC.ActivateWindow(MyPrograms)</onclick>
<visible>!Skin.HasSetting(noprograms)</visible>
</item>

replace it with the following:

Quote: <item id="2">
<label>HyperSpin</label>
<onclick>XBMC.RunScript(C:\program files\XBMC\launcher.py)</onclick>
<visible>!Skin.HasSetting(nogames)</visible>
</item>

Make sure the path to your python script (launcher.py) is correct. Save and exit.

++++++++++

Media Stream

Find the file 'home.xml'

by default under

\skin\MediaStream\720p\

from the XBMC root

open it and find the following:

Quote: <item id="4">
<description>My Programs Menu</description>
<label> $LOCALIZE[31004] </label>
<label2> $LOCALIZE[31014] </label2>
<visible>!Skin.HasSetting(HidePrograms)</visible>
<onclick>XBMC.ActivateWindow(1)</onclick>
</item>

and replace it with:

Quote: <item id="4">
<description>My Programs Menu</description>
<label>HyperSpin</label>
<label2>Launch</label2>
<visible>!Skin.HasSetting(HidePrograms)</visible>
<onclick>XBMC.RunScript(C:\program files\XBMC\launcher.py)</onclick>
</item>

Check that the path to the python script (launcher.py) is correct and save.

----------

well that's it - I know it's a long post, but it's mostly just checking that paths are correct.

NOTES:

The wrapper will work best if your desktop / XBMC / Hyperspin all are set to the same resolution.

KNOWN ISSUES:

The script will disable the 'programs/Games' feature of AEOn, however as many of you already know it is possible to add another main menu item. I was just lazy in implementation.

Please leave feedback / comments / requests below.

----------

As you can see the only vital parts are 1 and 4.
Reply
#2
Quick question for you. I have been trying to use the plugin Launcher to run the Hulu desktop app but XBMC does not minimize and thus my cpu resources are too high to run Hulu without frames lost. How would I incorporate your guide in order to run the Hulu desktop app?

thanks
Reply
#3
uncertainty Wrote:Quick question for you. I have been trying to use the plugin Launcher to run the Hulu desktop app but XBMC does not minimize and thus my cpu resources are too high to run Hulu without frames lost. How would I incorporate your guide in order to run the Hulu desktop app?

thanks

Alternatively, you can use EventGhost to minimize XBMX upon Hulu Desktop's launch and then maximize XBMC upon Hulu Desktop's exit.
Reply
#4
@ Uncertainty: I've had the same problem, since XBMC is on my laptop. My solution has always been 'wrappers' to close and reopen XBMC. And good news!

I've written one for you for hulu desktop. I have to say I'm pretty happy with it Smile

Launcher:
Code:
#SingleInstance force

;----------SET PATHS----------;
XBMC     = "C:\Program Files\XBMC\XBMC.exe"
HULU = "%LOCALAPPDATA%\HuluDesktop\HuluDesktop.exe"
;-----------------------------;

SetTitleMatchMode, 2
DetectHiddenWindows, On
Gui, Color, 000000
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
WinHide ahk_class Shell_TrayWnd
process, close, xbmc.exe
runwait, %HULU%,, UseErrorLevel
if ErrorLevel
{
    run, %XBMC% -fs,, UseErrorLevel
    if Errorlevel = ERROR
    {
        WinShow ahk_class Shell_TrayWnd
        gui, destroy
        blockinput, off
        msgbox, 0, ERROR, neither %XBMC% or %HULU% was found - Make sure you have correct paths, 4
        ExitApp
    }
    WinWait, XBMC, , 5
    IfWinNotActive, XBMC, , WinActivate, XBMC,
    WinWaitActive, XBMC, , 5
    if ErrorLevel
    {
        WinShow ahk_class Shell_TrayWnd
        gui, destroy
        ExitApp
    }
    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    ExitApp
}
WinWait, Hulu Desktop, ,5
IfWinNotActive, Hulu Desktop, , WinActivate, Hulu Desktop,
WinWaitActive, Hulu Desktop, ,4
WinShow ahk_class Shell_TrayWnd
gui, destroy
process, waitclose, huludesktop.exe

Gui, Color, 000000
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
WinHide ahk_class Shell_TrayWnd
run, %XBMC% -fs,, UseErrorLevel
if ErrorLevel
{
    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    msgbox, 0, ERROR, %XBMC%  was not found - Make sure you have correct paths, 4
    ExitApp
}
WinWait, XBMC
IfWinNotActive, XBMC, , WinActivate, XBMC,
WinWaitActive, XBMC, , 5
if ErrorLevel
{

    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    ExitApp
}
WinShow ahk_class Shell_TrayWnd
gui, destroy
blockinput, off
ExitAPP


python script:
Code:
import os, subprocess

subprocess.Popen(["c:\Program Files\xbmc\hululauncher.exe"], shell=False)

I have uploaded the compiled version of the script and the python script for you here. I understand if you don't trust an executable, which is why I supplied the source above so you can compile yourself.

This script essentially does the following:

draw a black screen, close xbmc, run hulu desktop, remove black screen.

Then pauses until hulu desktop closes and:

draws a black screen, launches xbmc, removes blackscreen.

This app is ~200kb and while running on my machine uses: 1800k of memory, which is due to it using cycles to check if hulu desktop is still open, but still better than xbmc in the background Smile

All you have to do is follow my above tutorial to call the python script (part 4). Or just sub the wrapper for the actual huludesktop in the program launcher. The only bug will be that it will return to the home screen instead of to the program launcher when you exit.

Enjoy, I actually think I'm gonna add this to my setup too!
Reply
#5
SophT, while this is certainly cool, you might want to have pointed out that AHK scripts are AutoHotKey files.

(reread your post about 200 times before i figured it out, found the program, and installed it)

that being said, the launchHulu.py results in the following error (taken from xbmc debug log):

03:31:35 T:2544 M:2944258048 NOTICE: -->Python Interpreter Initialized<--
03:31:35 T:2544 M:2944258048 DEBUG: XBPyThread:Tonguerocess - The source file to load is c:\program files\xbmc\launchHulu.py
03:31:35 T:2544 M:2944241664 DEBUG: XBPyThread:Tonguerocess - Setting the Python path to c:\program files\xbmc;special://xbmc/system/python/python24.zlib;special://xbmc/system/python/DLLs;special://xbmc/system/python/Lib;special://xbmc/system/python/spyce
03:31:35 T:2544 M:2944241664 DEBUG: XBPyThread:Tonguerocess - Entering source directory c:\program files\xbmc
03:31:35 T:2544 M:2944237568 NOTICE: File "
03:31:35 T:2544 M:2944237568 NOTICE: c:\program files\xbmc\launchHulu.py
03:31:35 T:2544 M:2944237568 NOTICE: ", line
03:31:35 T:2544 M:2944237568 NOTICE: 3
03:31:35 T:2544 M:2944237568 NOTICE: subprocess.Popen(["c:\Program Files\xbmc\hululauncher.exe"], shell=False)
03:31:35 T:2544 M:2944237568 NOTICE: ValueError
03:31:35 T:2544 M:2944237568 NOTICE: :
03:31:35 T:2544 M:2944237568 NOTICE: invalid \x escape
03:31:35 T:2544 M:2944237568 ERROR: Scriptresult: Error

are there any other things missing from your instructions other than autohotkey?
Reply
#6
oddly enough, the following works in launchhulu.py:

code:
Quote:import os
os.system("hululauncher.exe")
Reply
#7
I'm sorry that I forgot to mention autohotkey in my example. The main point of my post was really to be able to launch apps via the main menu with a simple python script.

I had originally used the version of the os.system like you just had but some people had problems with it on a 64bit O.S. os.system is the depricated version of the command in python, but still works.

does it work for you though?
Reply
#8
yes, os.system works and my system is 32bit XP.

thanks btw, i really like this and it solves a number of problems for me.

i have one question, bc i am not a coding guru like yourself, how would you modify the app launcher ahk script for detecting minimization of a window (as opposed to it closing)?

[oddness]
subprocess,Popen does work as well when i remove the path from the executable, i.e.:

Code:
subprocess.Popen(["hululauncher.exe"], shell=False)
Reply
#9
this is what i got, so far, and still have lots to figure out, but this script starts MyTheatre, and when minimized to tray, restarts XBMC.

(this is useful if you have your tv program constantly running in the background recording shows and the like.)

Sopht, please point out any obvious errors, since this is a butchering of your previous work:

1. I truncated the MYTHEATRE variable to just DVB (script would error on compile otherwise),
2. took out the detect hidden window statement, and
3. replaced "process, wait close" with just "winwait"


Code:
#SingleInstance force

;----------SET PATHS----------;
XBMC     = "C:\Program Files\XBMC\XBMC.exe"
DVB = "c:\MyTheatre\MyTheatre.exe"
;-----------------------------;

SetTitleMatchMode, 2
Gui, Color, 000000
Gui, -Caption +ToolWindow
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
WinHide ahk_class Shell_TrayWnd
process, close, xbmc.exe
runwait, %DVB%,, UseErrorLevel
if ErrorLevel
{
    run, %XBMC% -fs -p,, UseErrorLevel
    if Errorlevel = ERROR
    {
        WinShow ahk_class Shell_TrayWnd
        gui, destroy
        blockinput, off
        msgbox, 0, ERROR, neither %XBMC% or %DVB% was found - Make sure you have correct paths, 4
        ExitApp
    }
    WinWait, XBMC, , 5
    IfWinNotActive, XBMC, , WinActivate, XBMC,
    WinWaitActive, XBMC, , 5
    if ErrorLevel
    {
        WinShow ahk_class Shell_TrayWnd
        gui, destroy
        ExitApp
    }
    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    ExitApp
}
WinWait, Mytheatre, ,7
IfWinNotActive, MyTheatre, , WinActivate, Mytheatre,
WinWaitActive, MyTheatre, ,4
WinShow ahk_class Shell_TrayWnd
gui, destroy
WinWaitclose

Gui, Color, 000000
Gui, -Caption +ToolWindow +AlwaysOnTop
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,
WinHide ahk_class Shell_TrayWnd
run, %XBMC% -fs -p,, UseErrorLevel
if ErrorLevel
{
    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    msgbox, 0, ERROR, %XBMC%  was not found - Make sure you have correct paths, 4
    ExitApp
}
WinWait, XBMC
IfWinNotActive, XBMC, , WinActivate, XBMC,
WinWaitActive, XBMC, , 5
if ErrorLevel
{

    WinShow ahk_class Shell_TrayWnd
    gui, destroy
    blockinput, off
    ExitApp
}
WinShow ahk_class Shell_TrayWnd
gui, destroy
blockinput, off
ExitAPP
Reply
#10
Long time user of xbmc first post.

First of i would like to thank you for this noob friendly guide.

What does the -p stand for in the xlauncher script? I had troubles running the script. It lauched a different? version of xbmc, almost like a different profile where my backdrops etc didnt show. when i removed the -p in the launch xbmc line it acts normally. So just curiouseSmile

I used mala before but after this seamless integration of hyperspin i finnaly downloaded 40gig with artwork for a insane setupSmile and seamless integration.

In mala i had to use joytokey for exiting some of my emulators with a button press on my x360 controller.

So i was wondering what the line would look like for starting joytokey.exe
and then closing it when i close hyperspin? i hadnt even heard of .ahk before this amazing guideSmile So i use a /taskkill batch file in malaSmile
Reply
#11
the -p switch starts XBMC in "portable" mode, where the userdata folder is located in c:\program files\xbmc itself (so you can, for example, move it from installation to installation) as opposed to "C:\Documents and Settings\USERPROFILE\ etc etc)
Reply
#12
hellohello:

so you want this to happen:

open xbmc

run the launcher and launch that separate progam and close xbmc

minimize that second program and relaunch xbmc.

-----

Well I think first in the launcher we need to see if that program is already open (because what if you click on it, use it, return to xbmc, and click again - it's open 2, 3, 4, etc... times [unless it has an option to force a single instance])

Maybe something like this off the top of my head (change notepad to whatever program you want):

Code:
if WinExist, Notepad
{
  WinActivate
  WinMaximize
}
else
{
run, notepad.exe
}

as far as detecting when it's minimized I'm not sure the best way to do that. I'm thinking that using

Code:
WinWaitNotActive, Notepad

may work - but windows might consider it still 'active' because you haven't clicked another window.
Reply
#13
Excellent posting! I've been trying to find how to add items for along time.

One sticking point.. using the version of spinner.ahk posted by hellohello, I'm launching beyondtv. After exiting that program there is a 20 seconds pause at a blank screen before xbmc launches again. Is this something that can be shortened in the code somewhere?
Reply
#14
What am I doing wrongHuh


23:09:36 T:4048 M:2127360000 NOTICE: -->Python Interpreter Initialized<--
23:09:36 T:4048 M:2127355904 NOTICE:
23:09:39 T:2032 M:2135846912 NOTICE: -->Python Interpreter Initialized<--
23:09:39 T:2032 M:2135846912 NOTICE:
23:09:39 T:2032 M:2135822336 NOTICE: File "
23:09:39 T:2032 M:2135822336 NOTICE: C:\program files\XBMC\launcher.py
23:09:39 T:2032 M:2135822336 NOTICE: ", line
23:09:39 T:2032 M:2135822336 NOTICE: 2
23:09:39 T:2032 M:2135822336 NOTICE:
23:09:39 T:2032 M:2135822336 NOTICE:
23:09:39 T:2032 M:2135822336 NOTICE: os.system("hululauncher.exe") ], shell=False)
23:09:39 T:2032 M:2135822336 NOTICE:
23:09:39 T:2032 M:2135822336 NOTICE:
23:09:39 T:2032 M:2135822336 NOTICE:
...
23:09:39 T:2032 M:2135818240 NOTICE:
23:09:39 T:2032 M:2135818240 NOTICE:
23:09:39 T:2032 M:2135818240 NOTICE: ^
23:09:39 T:2032 M:2135818240 NOTICE: SyntaxError
23:09:39 T:2032 M:2135818240 NOTICE: :
23:09:39 T:2032 M:2135818240 NOTICE: invalid syntax
23:09:39 T:2032 M:2135818240 NOTICE:
23:09:39 T:2032 M:2135818240 ERROR: Scriptresult: Error
Reply
#15
This is the new error message:

"C:\PROGRA~1\XBMC\HULULA~1.EXEThe NTVDM CPU has encountered an illegal instruction.
CS:0dea IP:0241 OP:62 72 65 65 6e Choose 'Close' to terminate the application."

Now what's wrong?
Reply

Logout Mark Read Team Forum Stats Members Help
[MOD] Program Launcher Hack0