Retrieve Properties in a better way

I am a little confused at what you want to do.

Now there maybe mistakes in my understanding, as I am only learning myself…
But in this script,

The Available speakers are gathered in the SBElementArray speakers.
Each item in this SBElementArray is already an NSArray itself. I.e SBElementArray {item0=NSArray {“name”,“connected”,“other Stuff??”}, item1=NSArray {“name”,“connected”,“other Stuff”}.

The for function, executes its following statements on each NSArray item.

#import <Foundation/Foundation.h>
#import <ScriptingBridge/ScriptingBridge.h>
#import "Airfoil.h"
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   AirfoilApplication *Airfoil = [SBApplication applicationWithBundleIdentifier:@"com.rogueamoeba.Airfoil"];
	
SBElementArray * speakers =[Airfoil speakers] ;
	 
id item;
 
 if ([speakers count] > 0) {
 for (item in speakers) {
	 
	  NSLog(@" %@ <--This item is an Array inside the SBElementArry ",item);
	 NSNumber * conn = [NSNumber numberWithUnsignedInt:  [item connected]];
 NSString * displayedName= [item name];
	 NSLog(@"The Speaker %@    is   %@ (0 =not connected, 1 connected)", displayedName,conn);
	 
	 NSLog(@"Connecting the Speaker %@",displayedName);
	 [Airfoil connectTo:item password:nil];
	 conn = [NSNumber numberWithUnsignedInt:  [item connected]];
 NSLog(@"The Speaker %@    is   %@ (0 =not connected, 1 connected)", displayedName,conn);  
 }
 }
 [pool drain];
    return 0;
}

thanks for your help mark. After getting the list of the speakers with their connected state, I populate a tableview and then want to be able to either connect or disconnect to those speakers. Thanks to you I can now get the state of the speakers and populate this tableview. What I want to do is implement this part


- (void) connectTo:(NSArray *)x password:(NSString *)password; // Connect to the Airport Express speakers

of the Airfoil.h header file. I think I might have to do something like this

http://www.selvern.com/yanblog/2009/06/20/scripting-bridge/


QuickTimePlayerApplication *qt = [SBApplication applicationWithBundleIdentifier:@"com.apple. quicktimeplayer"];
QuickTimePlayerDocument *document = [[[qt classForScriptingClass:@"document"] alloc] init];
[[qt documents] addObject];

simply doing this

[Airfoil connectTo:setTheSpeaker password:nil]; 

doesn’t do anything.

I’m going to play around with it some more. And maybe post to the apple email list. http://lists.apple.com/index.html
If you haven’t used it I just used it for the first time yesterday and got some really good help with something else I was working on.

You need to read the documentation of SBElementArray.

objectWithName:

Is what you want, it lets you find the Object in the array whose name matches the string in the argument.
As opposed to the normal NSArray’s ObjectAtindex.

This script finds my Speaker named “Computer” and makes it Active (connected)

#import <Foundation/Foundation.h>
#import <ScriptingBridge/ScriptingBridge.h>
#import "Airfoil.h"
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   AirfoilApplication *Airfoil = [SBApplication applicationWithBundleIdentifier:@"com.rogueamoeba.Airfoil"];
	
	
	SBElementArray * speakers =[Airfoil speakers] ;
	
	id aSpeaker = [speakers objectWithName: @"Computer"];
	
	[Airfoil connectTo:aSpeaker password:nil];
	 NSString * displayedName= [aSpeaker name];
	NSNumber * conn = [NSNumber numberWithUnsignedInt:  [aSpeaker  connected]];
	
	NSLog(@"The Speaker %@    is   %@ (0 =not connected, 1 connected)", displayedName,conn);  
	
	
    [pool drain];
    return 0;
}

Don’t get me wrong, as i am enjoying this particular learning curve, But can I ask why you are re inventing the wheel?, Airfoil comes with its own control window that does what you are asking for??

thanks again mark. Now I see your previous post does what I want. Your patience and help has been amazing. I thought I had to create a new NSArray instead of passing the speaker SBElementArray. Makes sense though because I couldn’t figure out what keys needed to be in the array. I should have read over that section more carefully but since you can’t create an SBElementArray I thought it was only for getting objects not passing them back to an application. I actually thought I was learning something and figuring stuff guess I need to start going over my books and tutorials again.

I am creating an application that has a webview so you can listen to Pandora or grooveshark, etc and have airfoil just send the audio from that application to the speakers. At first I was just going to have it connect to all of the available speakers on startup and select the application as Airfoil’s target. But now I have a tableview that allows the user to select the available speakers and disconnect or connect. I know they could just do this through airfoil but eventually I wanted to connect to the speakers without airfoil. If I’m having this much trouble with reading the developer docs on Scripting Bridge it will be a while before that happens.

thanks again, it’s almost done so I’ll post it to google code and you can take a look at it. You wrote half of it so I’ll make sure to credit your name. :smiley:

Have you tried objc-appscript yet? I think you will find it much easier; the ASTranslate tool alone should answer many of your questions on how to convert AppleScript-style commands and references into ObjC syntax. Appscript’s only downside is that it isn’t included in the OS, so you have to download and build it yourself; however, it’s MIT-licensed so you can freely include the appscript framework in your application bundle when you come to distribute it.

I was glad to help, and thanks for credit, not necessary, but nice all the same.
I look forward to seeing the app.

All the best.

M.

Hi Has,

I having a look at this, And possibly being a bit thick, but where do I get the Appscript framework from??

Yeah, the website needs a little work. Anyway, it’s in the Subversion repository. To check out the current trunk (which includes documentation):

svn co https://appscript.svn.sourceforge.net/svnroot/appscript/objc-appscript/trunk objc-appscript-trunk

You’ll also need ASDictionary to generate ObjC glues. (And a copy of ASTranslate will be very useful too.)

If you plan on embedding the appscript framework in your application bundle, instructions can be found on Apple’s site.

HTH

Oo, k…

I have never used svn? I assume I have to download a front end to get that link to work?. Is the one that you can recommend.

I did find your appscript page and downloaded a appscript, not sure its the right one.

And I copied the framework into my user frameworks folder.
it does not show up in the stored list, so I have to still go and look for it.
If I make a project of my own, and add the framework, and the (finder) headers folder, some code from the translator, I can get it to compile. But not build. I suddenly get a load of errors.
( I set the build for 10.5)

I grabbed the ‘SelectFilesInFinder’ example.

Got errors on complie, and had to re point to it frameworks folder?, set it to 10.5,
Compiled ok, and built ok, ran ok.
Stripped the example code. Pasted mine. Ran ok.

Not sure what the problem is.

Ah,

Just set the build to $(NATIVE_ARCH) which was the only think I found not the same.

And it now works ok :D,

And :sigh: just found the Docs.

Many thanks.

Hi Has,

I thought I had solved this problem,
Now I have come to put the code into my app, It compiles and runs ok. But I need it for 10.5 ppc.

I have found because I am running 10.6 intel, It would not let me build for 10.5 ppc.
I get lots of build errors . Do you know what this issue could be??
My app was building and running for 10.5 ppc, ok before.
Some of the errors

Many Thanks

Make sure you build the Appscript framework as 2- or 4-way universal using the 10.4 or 10.5 SDK. I forget which configurations are in svn, but it sounds like you’re probably building the Debug version, which isn’t what you want. If none of the configurations currently in the project suit your needs, you can edit existing/create new configurations by selecting Targets->Appscript in the Groups&Files pane and clicking Cmd-I. If you’re not sure how to do that, I suggest you list all your requirements (universal; 32-bit or 32- and 64-bit?; garbage collection off/optional/required?; minimum OS version? for installing in a Library/Frameworks folder or embedding in a .app bundle?) and myself or someone familiar with Xcode can talk you through it.

FWIW, I’ve just checked in an update to objc-appscript in appscript’s Subversion repository that provides a better selection of ready-made build options.

HTH