How to use pathForResource: ??

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

How to use pathForResource: ??

Post by Wolfram »

Can some tell my what's wrong with this code?
I get the Error object is nil, but I think it does't need a object.

If you want to know what I'm trying to do: I want to get the path of the curser resource.

Code: Select all

 Path.s
CocoaMessage(@Path, 0, "pathForResource:$", @"cursor_1only_", "ofType:$", @"")
Debug Path
macOS Catalina 10.15.7
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to use pathForResource: ??

Post by Shardik »

You have to specify an NSBundle when calling method pathForResource:ofType:. Please take a look into the following working example which defines a bundle for TextEdit and displays the path to the file Edit.icns contained in TextEdit.app:

Code: Select all

; ----- Get NSBundle for TextEdit.app
TextEditBundle = CocoaMessage(0, 0,
  "NSBundle bundleWithPath:$", @"/Applications/TextEdit.app")

If TextEditBundle
  ; ----- Get path to file Edit.icns
  *Path = CocoaMessage(0, TextEditBundle,
    "pathForResource:$", @"Edit",
    "ofType:$", @"icns")
  Debug PeekS(CocoaMessage(0, *Path, "UTF8String"), -1, #PB_UTF8)
EndIf
Post Reply