All of my articles to date have been mostly about hardware. Now I feel it's worth while to start doing some XTension specific tutorials here.
This particular article started when I found a couple of run away programs using up a lot of CPU power. Yes, even on OSX a run away process can slow down others, it just can't stop them. The machine was running happily, just slowly. These other processes had nothing to do with XTension, just other apps that had fallen into an error condition while I wasn't looking. What that meant to my home automation setup was that when I opened the back door, the garage lights were taking 5 or7 seconds to turn on! This was horrible. I fixed the problem of the run away processes, but think this is a good idea anyway. It is very common for a Home Automation machine to be an older, slower box and you want to ensure that XTension gets the CPU time it needs to process events in a hurry and other things in the background can run a little slower. There is no reason for the No-IP client or the Weatherman X install to be a high priority. They will do their job in the background slower just fine. But you want XTension to respond to your remote or motion event as soon as possible.
This will only make a difference if you have a slower machine or a machine that is overloaded, or a machine with some greedy processes on it. If you're already running XTension alone on that brand new XServe it's not going to make any difference. However I also don't believe that it can cause any problems. You can set everything back to normal at any time, none of these changes are permanent and apply only until you quit the program.
There are 2 scripts that you'll need to either create or add to in order to do this. Because the changes aren't permanent the changes will need to be built into the startup procedure of XTension, so that whenever you run the app it adjusts it's priority. Luckily this is easy with XTension as there are applescripts that run during the startup procedure.
The following AppleScript will set the XTension program itself to a high priority. If you already have a global script named "Startup Script" then add this script to that. If you do not yet have a "Startup Script" create a new one from the Manage Global Scripts window.
set AdminPass to "YourAdminPassword"
set MyPID to (do shell script "ps axw | grep -i XTension.app | grep -v grep | grep -v .isf | cut -c 1-6")
write log "Renice XTension Process: " & MyPID
do shell script "echo " & AdminPass & " | sudo -S renice -20 " & MyPID
The unix command that does the work is the "renice" command, since it needs to be run with the admin password you'll have to fill in your administrator password at the beginning of this script. The second line of the script just gets the process ID number that has been assigned to XTension for this run. Since this goes into the startup script it will run whenever XTension is run and adjust the priority.
It's not enough to just adjust XTension though. Xtension uses helper background apps to do the work of talking to the various X10 and wireless interfaces. So those processes need to be adjusted as well. In the latest version of XTension there is a script that will run after starting these processes, just like the startup script will run after starting up the main application. This script is called "Init Interfaces Script" if you already have one add the following code to it, if you don't use the Manage Global Scripts window to create one with that name.
set AdminPass to "YourAdminPassword"
set MyPID to (do shell script "ps axw | grep -i .isf | grep -v grep | cut -c 1-6")
set saveddelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 13}
set ProcessCount to (count of text items in MyPID) as number
write log (ProcessCount as text) & " isf processes found"
repeat with i from 1 to ProcessCount
set ThisPID to text item i of MyPID
do shell script "echo " & AdminPass & " | sudo -S renice -20 " & ThisPID
write log "isf process " & ThisPID & " reset to high priority"
end repeat
set AppleScript's text item delimiters to {saveddelim}
This is basically the exact same script as the Startup Script, except that you can have multiple background helper apps running at once and so this will get a list of all of them and loop through the found process ID's until it has reniced them all to a high priority.