List of AppKit NSSound names
-
The documentation for NSSound says the name may be
"One of the named system sounds provided by the Application Kit"
By experimentation, I see that the names "Tink", "Basso", etc. (from
the Sound Preferences Panel) work fine as sound names. I wish to
construct a popup menu with these predefined sounds, but I feel
nervous about hardcoding the list... Is there documentation that lists
a minimum set of sound names that will always be present? Or is there
an API that gives me a list of sounds names? NSSound.h doesn't seem
to mention either, nor does a google search come up with much.
-- Tim Gogolin -
From what I've found, there doesn't appear to be a way to query for
a sounds list. Here's the code I use to build a sound list:
#define SystemLibrary() @"/System/Library/"
#define AllUsersLibrary() @"/Library/"
#define UserLibrary() [NSHomeDirectory()
stringByAppendingPathComponent:@"Library/"]
#define SoundsDirectory(base) [base
stringByAppendingPathComponent:@"Sounds"]
NSArray *knownSoundTypes = [NSSound soundUnfilteredFileTypes];
searchPaths = [NSArray arrayWithObjects:
SoundsDirectory(SystemLibrary()),
SoundsDirectory(AllUsersLibrary()),
SoundsDirectory(UserLibrary()),
nil];
e = [searchPaths objectEnumerator];
while (soundDirectory = [e nextObject])
{
if ([fm fileExistsAtPath:soundDirectory isDirectory:&isDir])
{
if (isDir)
{
fileEnum = [[fm
directoryContentsAtPath:soundDirectory] objectEnumerator];
while (soundFile = [fileEnum nextObject])
{
if ([knownSoundTypes containsObject:[soundFile
pathExtension]])
{
[sounds addObject:[soundFile
stringByDeletingPathExtension]];
}
}
}
}
}
sortedSounds = [[sounds allObjects]
sortedArrayUsingSelector:@selector(compare:)];
On Oct 27, 2005, at 8:03 AM, Tim Gogolin wrote:
> The documentation for NSSound says the name may be
> "One of the named system sounds provided by the Application Kit"
>
> By experimentation, I see that the names "Tink", "Basso", etc. (from
> the Sound Preferences Panel) work fine as sound names. I wish to
> construct a popup menu with these predefined sounds, but I feel
> nervous about hardcoding the list... Is there documentation that lists
> a minimum set of sound names that will always be present? Or is there
> an API that gives me a list of sounds names? NSSound.h doesn't seem
> to mention either, nor does a google search come up with much.
>
> -- Tim Gogolin
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<Cocoa-dev...>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<enigma0...>
>
> This email sent to <enigma0...>
>
-
Sean McBride wrote:
> On 2005-10-27 08:16, Ryan Britton said:
>
>> From what I've found, there doesn't appear to be a way to query for
>> a sounds list. Here's the code I use to build a sound list:
>>
>> #define SystemLibrary() @"/System/Library/"
>> #define AllUsersLibrary() @"/Library/"
>> #define UserLibrary() [NSHomeDirectory()
>> stringByAppendingPathComponent:@"Library/"]
>>
>> #define SoundsDirectory(base) [base
>> stringByAppendingPathComponent:@"Sounds"]
>>
>
> Better than hardcoding those paths is to use APIs like FSFindFolder
> () in
> Folders.h. That provides protection against Apple renaming the paths.
Possibly even better:
NSArray* libs = NSSearchPathForDirectoriesInDomains
(NSLibraryDirectory, NSUserDomainMask | NSLocalDomainMask |
NSSystemDomainMask, YES); -
On Oct 27, 2005, at 8:51 PM, Gregory Weston <gweston...> wrote:
> Sean McBride wrote:
>
>
>> On 2005-10-27 08:16, Ryan Britton said:
>>
>>
>>> From what I've found, there doesn't appear to be a way to query for
>>> a sounds list. Here's the code I use to build a sound list:
>>>
>>> #define SystemLibrary() @"/System/Library/"
>>> #define AllUsersLibrary() @"/Library/"
>>> #define UserLibrary() [NSHomeDirectory()
>>> stringByAppendingPathComponent:@"Library/"]
>>>
>>> #define SoundsDirectory(base) [base
>>> stringByAppendingPathComponent:@"Sounds"]
>>>
>>>
>>
>> Better than hardcoding those paths is to use APIs like FSFindFolder
>> () in
>> Folders.h. That provides protection against Apple renaming the
>> paths.
>>
>
> Possibly even better:
>
> NSArray* libs = NSSearchPathForDirectoriesInDomains
> (NSLibraryDirectory, NSUserDomainMask | NSLocalDomainMask |
> NSSystemDomainMask, YES);
Note that the NSSearchPathForDirectoriesInDomains function requires
Tiger.
Ben
--
Ben Kazez
http://www.benkazez.com -
Actually it's been around since 10.0.
Ali
>> NSArray* libs = NSSearchPathForDirectoriesInDomains
>> (NSLibraryDirectory, NSUserDomainMask | NSLocalDomainMask |
>> NSSystemDomainMask, YES);
>
> Note that the NSSearchPathForDirectoriesInDomains function requires
> Tiger.
>
> Ben
>
-
Oops, I'm totally wrong. NSSearchPathForDirectoriesInDomains does not
require Tiger; I had that impression because I recently used it to
search for NSApplicationSupportDirectory, which does require Tiger.
Ben
Begin forwarded message:
> From: Ben Kazez <kazezb...>
> Date: October 27, 2005 9:21:26 PM CDT
> To: <cocoa-dev...>, Gregory Weston <gweston...>
> Subject: Re: List of AppKit NSSound names
>
>
> On Oct 27, 2005, at 8:51 PM, Gregory Weston <gweston...> wrote:
>
>
>> Sean McBride wrote:
>>
>>
>>
>>> On 2005-10-27 08:16, Ryan Britton said:
>>>
>>>
>>>
>>>> From what I've found, there doesn't appear to be a way to query for
>>>> a sounds list. Here's the code I use to build a sound list:
>>>>
>>>> #define SystemLibrary() @"/System/Library/"
>>>> #define AllUsersLibrary() @"/Library/"
>>>> #define UserLibrary() [NSHomeDirectory()
>>>> stringByAppendingPathComponent:@"Library/"]
>>>>
>>>> #define SoundsDirectory(base) [base
>>>> stringByAppendingPathComponent:@"Sounds"]
>>>>
>>>>
>>>>
>>>
>>> Better than hardcoding those paths is to use APIs like FSFindFolder
>>> () in
>>> Folders.h. That provides protection against Apple renaming the
>>> paths.
>>>
>>>
>>
>> Possibly even better:
>>
>> NSArray* libs = NSSearchPathForDirectoriesInDomains
>> (NSLibraryDirectory, NSUserDomainMask | NSLocalDomainMask |
>> NSSystemDomainMask, YES);
>>
>
> Note that the NSSearchPathForDirectoriesInDomains function requires
> Tiger.
>
> Ben
> --
> Ben Kazez
> http://www.benkazez.com
>
-
On 2005-10-27 20:45, Gregory Weston said:
>> Better than hardcoding those paths is to use APIs like FSFindFolder
>> () in
>> Folders.h. That provides protection against Apple renaming the paths.
>
> Possibly even better:
>
> NSArray* libs = NSSearchPathForDirectoriesInDomains
> (NSLibraryDirectory, NSUserDomainMask | NSLocalDomainMask |
> NSSystemDomainMask, YES);
I really wish Cocoa had a nice API that did what FindFolder does, but
NSSearchPathForDirectoriesInDomains doesn't seem to be it. A quick
comparison of Folders.h and NSPathUtilities.h shows that the latter is
missing tonnes and tonnes of constants for all kinds of standard
folders, and yet it has seemingly nonsensical ones, like:
NSDemoApplicationDirectory, // unsupported applications, demonstration
versions (Demos)
NSAllApplicationsDirectory = 100, // all directories where applications
can occur
What the heck are these? Especially that last one, can't apps be
anywhere still? :)
--
____________________________________________________________
Sean McBride, B. Eng <sean...>
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada



