Re: Nsbundle help?
Re: Nsbundle help?
- Subject: Re: Nsbundle help?
- From: "John C. Welch" <email@hidden>
- Date: Tue, 12 Apr 2011 10:46:37 -0400
- Thread-topic: Nsbundle help?
Title: Re: Nsbundle help?
On 4/5/11 12:21 PM, "email@hidden" <email@hidden> wrote:
On 3 Apr 2011, at 02:31, John C. Welch wrote:
tell current application's NSBundle to set theBundle to bundleWithIdentifier_(theBundleID)
Which would then allow me to do things like:
set my theBundlePath to theBundle's executablePath()
However, when I try that one, I get:
[<NSObject 0x7fff70154468> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key theBundlePath.
Try it without the 'my' if you want to set a local variable named theBundlePath.
Otherwise you probably need to define an NSObject class property named theBundlePath.
So with this code:
script nsbundletestAppDelegate
property parent : class "NSObject"
property theBundleURL:""
on applicationWillFinishLaunching_(aNotification)
set theBundleURL to ""
set theBundleID to "com.apple.nke.asp_tcp"
tell current application's NSBundle to set theBundle to bundleWithIdentifier_(theBundleID)
set theBundleURL to theBundle's bundleURL()
log (theBundleURL as text)
end applicationWillFinishLaunching_
end script
I get: 2011-04-12 10:30:30.928 nsbundletest[895:903] *** -[nsbundletestAppDelegate applicationWillFinishLaunching:]: The variable theBundleURL is not defined. (error -2753)
Adding the my to anywhere but the log statement gets me the same error. Adding the my to the log statement gets me:
2011-04-12 10:34:10.433 nsbundletest[946:903] [<NSObject 0x7fff70154468> valueForUndefinedKey:]: this class is not key value coding-compliant for the key theBundleURL.
Am I just completely misunderstanding what NSBundle is actually doing here, because I can’t see why this isn’t working. The only thing that makes sense is that something is going very very wrong when I’m either setting theBundle or theBundleURL. Does NSBundle actually let you search for <random bundle> with and specified ID, or does it ONLY let you use it with a bundle YOU created?
The documentation on this is not terribly clear:
bundleWithIdentifier:
Returns the previously created NSBundle instance that has the specified bundle identifier.
+ (NSBundle *)bundleWithIdentifier:(NSString *)identifier
Parameters
identifier
The identifier for an existing NSBundle instance.
Return Value
The previously created NSBundle instance that has the bundle identifier identifier. Returns nil if the requested bundle is not found.
However, that would seem to be the case, since this:
script nsbundletestAppDelegate
property parent : class "NSObject"
property theBundleURL:""
on applicationWillFinishLaunching_(aNotification)
set my theBundleURL to "foo"
log theBundleURL
tell current application's NSString to set theBundleID to alloc()'s initWithString_("com.apple.nke.asp_tcp")
log theBundleID
tell current application's NSBundle to set theBundle to bundleWithIdentifier_(theBundleID)
if theBundle is (missing value) then
log "no bundle"
end if
set theBundleURL to theBundle's bundleURL()
log (theBundleURL as text)
end applicationWillFinishLaunching_
end script
Tells me that there is no bundle. Sigh.
--
"The only easy day was yesterday."
US Navy SEALs
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden