1

macOS comes with a bunch of predefined images (Folder, Trash, ...) I can use the NSImage(named: "") here to get the image.

It looks like some of the images are stored in /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/

There are also images of all the Apple devices. Is there a way to get the images using Swift? I tried using the filename with NSImage(named: ""), but nil is returned.

inexcitus
  • 2,471
  • 2
  • 26
  • 41
  • 1
    `NSImage(named: NSImageNameComputer)` is the standard way of getting the machine icon. There used to be a way to easily get higher resolutions: https://stackoverflow.com/a/32381289/2227743, but it doesn't work anymore. The not easy way should still work, though: https://stackoverflow.com/a/32373977/2227743. – Eric Aya Jun 18 '17 at 11:39
  • Wow, that was easy, thank you. The image that is returned with the first method seems pretty high resolution to me, so I'll stick with that one. – inexcitus Jun 18 '17 at 11:54
  • 1
    Cool! You're welcome. I'm closing this question as a duplicate of the other one, since this is where I got this method from (Marek's answer). – Eric Aya Jun 18 '17 at 11:57
  • Can I get the folder icons of the "Library", "User" and "Applications" folder in a similar way? – inexcitus Jun 22 '17 at 17:43
  • 1
    Available ones are listed here: https://developer.apple.com/documentation/appkit/nsimage.name But I don't see the ones you want. So, the answer is no (or rather: I don't think so). – Eric Aya Jun 22 '17 at 17:54
  • I also found the constant "kApplicationsFolderIcon" but I don't know how/where to use it. – inexcitus Jun 22 '17 at 17:56
  • 1
    No constant, but you can get a specific folder icon by giving its path: `NSWorkspace.shared().icon(forFile: "/Applications")`. – Eric Aya Jun 28 '17 at 13:18

0 Answers0