<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vincent Gable's Blog &#187; NSApplicationName</title>
	<atom:link href="http://vgable.com/blog/tag/nsapplicationname/feed/" rel="self" type="application/rss+xml" />
	<link>http://vgable.com/blog</link>
	<description>my weblog.</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>NSApplicationName Inconsistencies</title>
		<link>http://vgable.com/blog/2008/07/03/nsapplicationname-inconsistencies/</link>
		<comments>http://vgable.com/blog/2008/07/03/nsapplicationname-inconsistencies/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 00:06:18 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[File Systems]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSApplicationName]]></category>
		<category><![CDATA[Paths]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2008/07/03/nsapplicationname-inconsistencies/</guid>
		<description><![CDATA[The value stored under the NSApplicationName key of the result of [[NSWorkspace sharedWorkspace] activeApplication] is not the always the name the user knows the application by. Worse, it&#8217;s not always the same as the name for the application that other APIs expect or return. Even fullPathForApplication: in NSWorkspace sometimes won&#8217;t recognize it! The problem stems [...]]]></description>
			<content:encoded><![CDATA[<p>The value stored under the <code>NSApplicationName</code> key of the result of <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWorkspace/activeApplication"><code>[[NSWorkspace sharedWorkspace] activeApplication]</code></a> is not the always the name the user knows the application by.  Worse, it&#8217;s not always the same as the name for the application that other APIs expect or return.  Even <code>fullPathForApplication:</code> in NSWorkspace sometimes won&#8217;t recognize it!</p>
<blockquote><p>
The problem stems from the fact that there are at least five application names floating around, at least in concept: (1) the file name the Finder sees, which in the case of an application package is the package (bundle) name; (2) the name of the executable inside the package, (3) the long name used in many places for display purposes only; (4) the short name used as the application menu title and in a few other places where a long name won&#8217;t fit for display purposes; and (5) the process name of a running application. They aren&#8217;t always the same, especially in Microsoft and Adobe products.
</p></blockquote>
<p>&#8211;From <a href="http://www.cocoabuilder.com/archive/message/cocoa/2003/8/24/2349">an informative message</a> by <a href="http://www.quecheesoftware.com/">Bill Cheeseman</a>.</p>
<p>So instead of relying on <code>NSApplicationName</code> I now use <code> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/displayNameAtPath:">-[[NSFileManager defaultManager] displayNameAtPath:]</a></code>  then strip off the filename extension.  This should give exactly the filename the user sees.  Every time.</p>
<p><code><br />
NSDictionary *appInfo = [[NSWorkspace sharedWorkspace] activeApplication];<br />
NSString *appPath = [appInfo objectForKey:@"NSApplicationPath"];<br />
NSString     *name = [[[NSFileManager defaultManager] displayNameAtPath:appPath] stringByDeletingPathExtension];</code></p>
<p><strong><a href="http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFBundles/Tasks/locating.html#//apple_ref/doc/uid/20001123-123081">And of course, you really should be using bundle identifiers, instead of names, to identify an application.</a></strong>  Unfortunately, a <em>very few</em> applications are not bundles.  (For example, Microsoft stuff prior to Office 2008), so it <em>might</em> be necessary to fall back on using a name to locate them in a path-independent way.</p>
<p>Creating a custom <code>CFBundleName</code> in an application&#8217;s <code>info.plist</code> file seems to confuse <code>NSApplicationName</code>.  For this reason I don&#8217;t think setting it is a good idea.</p>
<p>UPDATE 2010-01-20: See also, <a href="https://developer.apple.com/mac/library/qa/qa2007/qa1544.html"><cite>Technical Q&#038;A QA1544: Obtaining the localized application name in Cocoa</cite></a></p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2008/07/03/nsapplicationname-inconsistencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

