Support
All support resources for our products. Here you can find answers to frequently asked questions, discuss with other users, recover a lost license code or file a support request.
Forum closed
This forum was closed and turned into an archive effective April 21, 2018. It is no longer possible to create new topics or reply to existing topics.

Thanks everyone for all the great questions and contributions over the years.

Please use the Contact form to get in touch.

Remote Buddy Forum

Overview 

AuthorThread
User

19.09.2010 08:51:58
Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Hi;

I want to be able to index up and down through the cable TV channels, not all of which I am subscribed to, using the forward and backwards keys.

I have actions mapped to the numbers 0-9 in a custom behavior and so I would want to do something like this:

array(100,110,123,150,200,201,495.700,877,900) 
dim i = 0 
if press = up then i=i+1 
else i=i-1 
var chan = array[i] 
send chan as keypresses

I guess that this would have to be done with applescript, but how am I going to know which was the last channel selected as I don't think that applesecript supports session variables ??

I somehow need to make the index variable (i) persistent so that each time the script is run it will continue fro the previous index value ??

Thanks

PeterC

These entries from the FAQ may be relevant to this topic:

Configuration
Hardware - Apple® Remote
User

20.09.2010 04:07:28
Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
The following script increments the index and displays the correct channel data when I compile and execute it using the Applescript Editor, i.e. the 'index' property is persistent and survives each execution of the script, but when I run the same script in RB it always displays the first channel and it looks like the index property is not persistent in RB ?

[code] 
set chans to {441, 447, 501, 502} 
set chCount to count chans 
property index : 0 
set index to index + 1 
if index > chCount then set index to 1 
set chan to item index of chans 
set x100 to round chan / 100 rounding down 
set x10 to round (chan - x100 * 100) / 10 rounding down 
set x1 to round chan mod 10

--display dialog x100 
--display dialog x10 
--display dialog x1 
[/code] 

User

24.09.2010 13:35:47
Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Bump....

Anybody there ??? 

User

27.09.2010 09:10:47
Re: Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Thanks for asking.

Chances are AppleScript properties aren't globally permanent (if they were, they'd also be in Remote Buddy).

Remote Buddy supplies dedicated commands to store and retrieve values temporarily (in memory) or permanently (on disk). You can find documentation and sample code for both in Remote Buddy's AppleScript dictionary.

Best regards, 
Felix Schwarz 

User

27.09.2010 09:44:10
Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Hi Felix;

Thanks, but the script works perfectly when I compile and execute it using the Applescript Script Editor, on the same machine which RB is running on.

If I then cut and paste the exact code from the script editor into RB it does not work, so the property IS globally persistent when run in applescript editor but IS NOT globally persistent in RB ??!

Maybe you can test it and see ??

Thanks

 

User

27.09.2010 11:15:02
Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Anyway, I managed to use the RB read & store and hopefully this will prove useful for someone else who is looking to do the same thing.

[code] 
set chans to {146, 403, 404, 407, 411, 412, 413, 422, 423, 424, 425, 426, 427, 432, 435, 441, 447, 501, 502, 503, 511, 512, 515, 521, 522, 523, 525, 531, 532, 533, 615, 616} 
set chCount to count chans

tell application "Remote Buddy" 
read value for key "com.pac.chno" in domain "temporary" 
if (result is missing value) then 
store value "0" for key "com.pac.chno" in domain "temporary" 
set chno to "0" 
else 
set chno to result 
end if 
set chno to chno + 1 
if chno > chCount then set chno to 1 
store value chno for key "com.pac.chno" in domain "temporary" 
end tell

--property chno : 0 
set chan to item chno of chans 
set x100 to round chan / 100 rounding down 
set x10 to round (chan mod 100) / 10 rounding down 
set x1 to round chan mod 10 
set x100 to x100 + 4 
set x10 to x10 + 4 
set x1 to x1 + 4

tell application "iRed.app" to «event IRDaIRsc» given «class IRsC»:«class IRAA» x100 of «class IRAC» "SCV" 
--display dialog x100 
delay 0.25 
tell application "iRed.app" to «event IRDaIRsc» given «class IRsC»:«class IRAA» x10 of «class IRAC» "SCV" 
--display dialog x10 
delay 0.25 
tell application "iRed.app" to «event IRDaIRsc» given «class IRsC»:«class IRAA» x1 of «class IRAC» "SCV" 
--display dialog x1 
[/code] 

User

27.09.2010 18:13:46
Re: Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
AppleScript properties are not globally persistent. They don't survive recompilations. They are not stored on disk. Reference: http://www.macobserver.com/tips/applescript/2002/20020529.shtml, paragraph "The Last Word".

Remote Buddy stores the script *source code* and compiles it when needed. It doesn't store compiled versions in memory (to save memory). AppleScript Editor appears to do this. And it certainly makes sense in its case - it will usually not have to manage hundreds or even thousands of scripts at once (like Remote Buddy).

Thus the difference.

Best regards, 
Felix Schwarz 

User

28.09.2010 09:49:08
Re: Index through an array of channels
View

This posting is older than 6 months and can contain outdated information.
Hi Felix;

The key thing (which I was not previously aware of) is the fact that the script is compiled before each execution, if it was only compiled once then the property method would work, as it does when compiling the script once but executing it may times using the applescript editor.

Your explanation as to why this is done sounds very logical, and I am now using the store / read method you suggested sucessfully.

I will use this method as well to create a 'toggle' script which toggles 2 different actions on each alternate key press.

Thanks for your help

PeterC

Last edited: 28.09.2010 09:50:03