How do I get Mac system icons, as in the Finder? - cocoa

I want to set the images in my outline view to the system icons, just like on the left in the Finder. I want to get icons like Application, Documents, Desktop, etc. How do I do this?

Use NSWorkspace's iconForFile: method
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:#"/Applications/"];
edit:
take a look at these files, are they what you're after? Your question is a little hard to understand
$ ls /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Toolbar*FolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarAppsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDesktopFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDocumentsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDownloadsFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarLibraryFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarMovieFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarMusicFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarPicturesFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarPublicFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarSitesFolderIcon.icns
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarUtilitiesFolderIcon.icns

There's a method in NSWorkspace that allows you to set custom icons to folders and files:
- (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath
options:(NSWorkspaceIconCreationOptions)options
Sets the icon for the file or directory at the specified path.

Use -[NSWorkspace iconForFileType:], and pass constants from IconsCore.h (filtered through NSFileTypeForHFSTypeCode, of course).

This article on Creating icns Icon Files should cover what you want to do. There is also an article on creating an icon so that it looks similar to the standard folder icon, which is good for consistency. Hope that helps.
Of course, this isn't really programming related.

Related

macOS Touch Bar Icons Location

New MacBook Pro's with Touch Bar, in macOS Sierra, icons for the system control strip, where would they be located?
I looked under HD/System/Library/CoreServices, not there.....
The Touch Bar system icons are all located in /System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/Assets.car.
To name a few examples, they are named like TouchBarControlStripSpotlight or TouchBarControlStripSiriContent.
If you want to inspect and also change them you can use the ThemeEngine app to open the .CAR files. You can find the app/project here: https://github.com/alexzielenski/ThemeEngine
Sadly the ThemeEngine.app fails to display all icons. Some appear to be empty, but I guess thats a problem with the app. Maybe there's another, more reliable way to open .CAR files.
Touch Bar is introducing these new icons:
Here are the references: (You can find them and all others images in NSImage.h)
NSImageNameTouchBarAddDetailTemplate,
NSImageNameTouchBarAddTemplate,
NSImageNameTouchBarAlarmTemplate,
NSImageNameTouchBarAudioInputMuteTemplate,
NSImageNameTouchBarAudioInputTemplate,
NSImageNameTouchBarAudioOutputMuteTemplate,
NSImageNameTouchBarAudioOutputVolumeHighTemplate,
NSImageNameTouchBarAudioOutputVolumeLowTemplate,
NSImageNameTouchBarAudioOutputVolumeMediumTemplate,
NSImageNameTouchBarAudioOutputVolumeOffTemplate,
NSImageNameTouchBarBookmarksTemplate,
NSImageNameTouchBarColorPickerFill,
NSImageNameTouchBarColorPickerFont,
NSImageNameTouchBarColorPickerStroke,
NSImageNameTouchBarCommunicationAudioTemplate,
NSImageNameTouchBarCommunicationVideoTemplate,
NSImageNameTouchBarComposeTemplate,
NSImageNameTouchBarDeleteTemplate,
NSImageNameTouchBarDownloadTemplate,
NSImageNameTouchBarEnterFullScreenTemplate,
NSImageNameTouchBarExitFullScreenTemplate,
NSImageNameTouchBarFastForwardTemplate,
NSImageNameTouchBarFolderCopyToTemplate,
NSImageNameTouchBarFolderMoveToTemplate,
NSImageNameTouchBarFolderTemplate,
NSImageNameTouchBarGetInfoTemplate,
NSImageNameTouchBarGoBackTemplate,
NSImageNameTouchBarGoDownTemplate,
NSImageNameTouchBarGoForwardTemplate,
NSImageNameTouchBarGoUpTemplate,
NSImageNameTouchBarHistoryTemplate,
NSImageNameTouchBarIconViewTemplate,
NSImageNameTouchBarListViewTemplate,
NSImageNameTouchBarMailTemplate,
NSImageNameTouchBarNewFolderTemplate,
NSImageNameTouchBarNewMessageTemplate,
NSImageNameTouchBarOpenInBrowserTemplate,
NSImageNameTouchBarPauseTemplate,
NSImageNameTouchBarPlayheadTemplate,
NSImageNameTouchBarPlayPauseTemplate,
NSImageNameTouchBarPlayTemplate,
NSImageNameTouchBarQuickLookTemplate,
NSImageNameTouchBarRecordStartTemplate,
NSImageNameTouchBarRecordStopTemplate,
NSImageNameTouchBarRefreshTemplate,
NSImageNameTouchBarRewindTemplate,
NSImageNameTouchBarRotateLeftTemplate,
NSImageNameTouchBarRotateRightTemplate,
NSImageNameTouchBarSearchTemplate,
NSImageNameTouchBarShareTemplate,
NSImageNameTouchBarSidebarTemplate,
NSImageNameTouchBarSkipAhead15SecondsTemplate,
NSImageNameTouchBarSkipAhead30SecondsTemplate,
NSImageNameTouchBarSkipAheadTemplate,
NSImageNameTouchBarSkipBack15SecondsTemplate,
NSImageNameTouchBarSkipBack30SecondsTemplate,
NSImageNameTouchBarSkipBackTemplate,
NSImageNameTouchBarSkipToEndTemplate,
NSImageNameTouchBarSkipToStartTemplate,
NSImageNameTouchBarSlideshowTemplate,
NSImageNameTouchBarTagIconTemplate,
NSImageNameTouchBarTextBoldTemplate,
NSImageNameTouchBarTextBoxTemplate,
NSImageNameTouchBarTextCenterAlignTemplate,
NSImageNameTouchBarTextItalicTemplate,
NSImageNameTouchBarTextJustifiedAlignTemplate,
NSImageNameTouchBarTextLeftAlignTemplate,
NSImageNameTouchBarTextListTemplate,
NSImageNameTouchBarTextRightAlignTemplate,
NSImageNameTouchBarTextStrikethroughTemplate,
NSImageNameTouchBarTextUnderlineTemplate,
NSImageNameTouchBarUserAddTemplate,
NSImageNameTouchBarUserGroupTemplate,
NSImageNameTouchBarUserTemplate
Example use in Obj-C:
NSImage *image = [NSImage imageNamed:NSImageNameTouchBarUserTemplate];
Example use in Swift:
let image = NSImage(named: NSImageNameTouchBarUserTemplate)
If you're interested in customizing the touch bar icons Apple provides some templates to get started:
And while they're not specific to the touch bar – which has its own design guidelines – there's a bevy of additional design resources available on the HIG.

Xcode debugging - displaying images

I love using the Xcode debugger. You can take a look at a variable's value and even change it.
But can I somehow DISPLAY the image that is referenced by an image variable? I know I can see its raw bytes, but it would be much more human-friendly to display a window with its contents.
Xcode might not support this. Maybe there is an external tool that would help display images?
Use Quick Look to inspect images in the Xcode debugger.
Select an NSImage or UIImage in the debugger, then click the Quick Look "eye" icon.
Like other areas of OS X, you can also use spacebar to Quick Look!
Quick Look in the debugger can also be implemented for your own classes:
Enabling Quick Look for Custom Types
The variables Quick Look feature in the Xcode debugger allows you to obtain a quick visual assessment of the state of an object variable through a graphical rendering, displayed in a popover window either in the debugger variables view or in place in your source code.
This chapter describes how you implement a Quick Look method for your custom class types so that object variables of those types can also be rendered visually in the Quick Look popover window.
If you like to work with the lldb console, use chisel command "visualize"
tip:
after the installation, you can set a conditional breakpoint after setting the UIImage with the action:
"visualize myUIImageToShowWithQuickLook"
this will show you the image automatically when the debugger stops.
EDIT:
As of Xcode 5, the debugger can show you the visual representation of UIImage/CGImageRef variables!
Xcode itself can't do it. I don't know about external tools.
What i'm doing to test images while debugging is to convert that raw data into an image-file format, like .png, and then saving it somewhere, and then i'm opening the image with any image viewing tool.
I have a piece of code for that purpose, which look basically like that:
NSData *imageData = UIImagePNGRepresentation(self.myUIImage);
[imageData writeToURL:desktopURL atomically:YES];
And i'm just copy-pasting this code where i want to see content of an image on the run.
Make sure to get rid of this code as soon as possible due to the high-cost of the conversion of UIImage to NSData
Edit for Xcode 5: Now when you hover over an image variable name, there is an "eye" icon on the right. Just click it to see the current image!
NOTE: sometimes this fails in Xcode, even if the image is correct. If this happens, OR if you don't have a UIImage variable (e.g. it's a property of another object, you can still use the older answer:
Older answer: Starting with Avraham's answer, I tried a few experiments for displaying an iOS image from lldb without having to recompile or add it to a view. I finally came up with:
e [UIImagePNGRepresentation(myImage) writeToFile:#"/Users/<userName>/Desktop/myImage.png" atomically:NO];
I keep this string in a text editor and paste it when I need it. This stores the current image I'm interested in (in this case, "myImage") to a PNG file on the Desktop. Then I can just open this file with Preview.
If you're working on an iOS device, then you can use
e [UIImagePNGRepresentation(myImage) writeToFile:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingString:#"/myImage.png"] atomically:NO];
Then you can use the Finder; select your device; "Files"; then your dev app, and copy the image to your Desktop to view it.
What if you can't get to the image via the variables view?
Echoing what #pkamb said - you can use the variables view to quick look at an image. But what if you can't get to the image?
for example I have an image at (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image
but if I try to expand contentViewController in the variable view it doesn't expose my subviews
what you can do is right click, add an expression, and then you can see it!
Click the eye icon when hovering over a variable in Xcode:
You can put a breakpoint in the line of your image, and then in the debugger, just write:
po your_UIImage_object
po stands for print object, it's a GDB command which will display several useful informations about the object passed, in your case the image.

What is the name of this Mac OS X control?

Does this control have a name? Or is it just a bunch of simple controls merged together? If so, what controls are they?
http://img8.imageshack.us/img8/3002/picture2xrb.png
It looks like an NSTableView with an a custom cell type and no column header. Have a look at the documentation for NSTableView's tableView:dataCellForTableColumn:row:. For columns which have the same type for all rows you may also set the cell class in interface builder.
I doubt the search box is part of the same control.
You could open the Application's Nib file to see what is in there. Look inside the application bundle. If the application is called Example then you should be able to find the Nib at Example.app/Contents/Resources/English.lproj/MainMenu.nib.
The best tool for investigating this is fscript, specifically FScriptAnywhere which will let you determine the class and much other information about any visual element of any Cocoa program (and do a lot of other interesting things with Cocoa programs).
In addition to what toholio said, an easy way to get the look and feel of the bottom button bar is with BWToolkit.

Which function does Leopard's Finder get the preview icons with the watermark on them?

I already took a look at GetIconRefFromFileInfo() and QLThumbnailImageCreate() but they just doesn't seem to be similar with what I see from the finder, which is a square icon with watermarks on it, e.g. if the file is RTF, it has this greyish watermark below that says RTF or RTFD or PDF...
Please help me out on this. Thanks. If the question is still unclear, please feel free to comment.
From MacScripter:
This is a category on NSImage which
lets you get an image containing a
Quick Look preview of the content of a
given file. If no Quick Look preview
is available, it will instead return
the file's Finder icon (this is what
the Quick Look panel does). It
consists of only one method:
+ (NSImage *) imageWithPreviewOfFileAtPath: (NSString*) path ofSize: (NSSize) size asIcon: (BOOL) icon

Handle OSX Dock Drag N Drop

I looked high and low for information on how to handle drag n drop to the dock in OSX. The drag n drop documentation (http://developer.apple.com/documentation/Cocoa/Conceptual/DragandDrop/DragandDrop.html#//apple_ref/doc/uid/10000069) I found all deal with dragging from view to view. If anyone can point me to some code samples, that would be excellent.
I'm writing my app using the PyObjC bride, but Cocoa examples would be equally welcome :-)
Well, looks like I asked too soon. Here is a great tutorial that shows how one does it:
http://recurser.com/articles/2007/04/13/cocoa-drag-to-dock-to-open/
Basically, just set your controller to be the delegate of NSApplication and implement the openFile method.
Here's a similar question from a couple weeks ago. My answer covered dragging files, which is what you're talking about; the other answer covers dragging data, such as images and bits of text (not image files or text files, but bare data).
http://lethain.com/entry/2008/aug/06/cocoa-drag-and-drop-text-into-the-dock-icon/ covers dragging and dropping text into a dock icon with pyobjc. You can adapt this into other files reasonably easily.
Here is a newer article for Xcode 4
http://fredandrandall.com/blog/2011/09/12/how-to-open-any-file-you-drag-onto-your-apps-dock-icon
Here is an example project "DockDrop".

Resources