Thanks Chris,
Is there any particular reason you're not using function parameters and return values? QA1111 <
http://developer.apple.com/qa/qa2001/qa1111.html> has sample code for doing this -- it's generally more straightforward than mucking around with property values.
I saw that article, and frankly, I found the number of new concepts in there daunting in comparison to OSASetProperty. My focus was mainly on 'getting something working' and not on 'understanding how AppleEvents underpins AppleScript', and I saw enough in there to scare me away (such as this argument to AEBuildAppleEvent: "'----':[TEXT(@),TEXT(@),TEXT(@),TEXT(@),alis(@@)],'snam':TEXT(@)").
Incidentally, I discovered, through trial and error, the solution to my problem. Though there was nothing wrong with the code snippet I posted here, there were two other problems. (I'll be explicit here just in case someone else has the same problem.)
First, even though I specified my property in my applescript using mixed case, OSASetProperty seemed to insist that I use all lower-case. I discovered this by using OSAGetPropertyNames() and the following code:
AEDescList proplist;
ON_ERROR( OSAGetPropertyNames( _scriptingComponent, kOSAModeNull,
_script_id, &proplist ) );
SInt32 item_count = -1;
ON_ERROR( AECountItems(&proplist, &item_count) );
for ( SInt32 i = 1; i <= item_count; i++ )
{
AEKeyword theKeyword;
AEDesc theItem;
ON_ERROR( AEGetNthDesc( &proplist, i, typeChar, &theKeyword,
&theItem ) );
std::string text;
Size size = AEGetDescDataSize( &theItem );
std::vector<char> buf( size );
AEGetDescData( &theItem, &buf[0], size );
std::copy( buf.begin(), buf.end(), std::back_inserter( text ) );
std::cout << text << "\n";
}
(ON_ERROR is just a macro that calls a function that throws an exception with __FILE__ and __LINE__ if an error occurs).
The second problem was this: when calling OSALoadFile() or OSACompile(), I had to pass kOSAModeCompileIntoContext and not kOSAModeNull as the mode argument. I don't have any idea why this is necessary, as this discovery was made by the beating-on-the-black-box-until-it-did-something-different mode of troubleshooting.
Now, lest everyone forms the opinion of me that I'm just some incorrigible hack, let me say this: I have no aversions to spending time learning how a new (to me) framework works, and how to properly implement things using that new framework. But this passing of data problem is such a minor part of this application that it did not seem to warrant a major expenditure in time. (That said, in this case the time it took beating-on-the-black-box _may_ have exceeded the time it would have taken to fully grok the suggested article ;)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list (
Applescript-implementors@list...)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/subscriber%40opensubscriber.com
This email sent to
subscriber@open...
opensubscriber is not affiliated with the authors of this message nor responsible for its content.