Re: How to tell if iTunes is running.

2008-05-24 Thread has

Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.


iTunesIsOpen = NO;
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSString* iTunesPath = [workspace  
absolutePathForAppBundleWithIdentifier:@"com.apple.iTunes"];

NSArray* lApplications = [workspace launchedApplications];
int lAppsCount = [lApplications count];
int a;
for (a = 0; a < lAppsCount; a++)
{
NSDictionary* applicationD = [lApplications objectAtIndex:a];
if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])

{
iTunesIsOpen = YES;
break;
}
}


Yeah, bundle IDs are a good habit. Here's a slightly cleaner, case- 
insensitive version of the above:


BOOL IsRunning(NSString *bundleID) {
	NSEnumerator *appsList = [[[NSWorkspace sharedWorkspace]  
launchedApplications] objectEnumerator];

NSDictionary *appInfo;
bundleID = [bundleID lowercaseString];
while (appInfo = [appsList nextObject]) {
		if ([[[appInfo objectForKey: @"NSApplicationBundleIdentifier"]  
lowercaseString] isEqual: bundleID])

return YES;
}
return NO;
}


Or just use one of the ObjC-AppleEvent bridges to do everything. For  
example, using objc-appscript:


#import 
#import "ITGlue/ITGlue.h"

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	ITApplication *itunes = [[ITApplication alloc] initWithBundleID:  
@"com.apple.itunes"];


NSLog(@"Is running: %i", [itunes isRunning]);

[[itunes run] send];

NSLog(@"Is running: %i", [itunes isRunning]);

[[itunes quit] send];

while([itunes isRunning]) {
printf("Waiting while iTunes quits...\n");
sleep(1);
}

NSLog(@"Is running: %i", [itunes isRunning]);

[itunes release];
[pool release];
return 0;
}

HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Mr. Gecko
I agree that the bundle identifier is more reliable thanks for the  
tip. I am going to be using it

On May 24, 2008, at 4:11 PM, Jens Alfke wrote:



On 24 May '08, at 12:05 PM, Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.

...
 if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])


It would be simpler just to use the "NSApplicationBundleIdentifier"  
key, comparing it with "com.apple.iTunes".


—Jens


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Steve Christensen

On May 24, 2008, at 2:11 PM, Jens Alfke wrote:


On 24 May '08, at 12:05 PM, Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.

...
  if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])


It would be simpler just to use the "NSApplicationBundleIdentifier"  
key, comparing it with "com.apple.iTunes".


I didn't see that in the headers but it is in the docs. Yes, that'd  
work better.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Steve Christensen
My version wasn't about using the path for something else; it was  
only about providing a method that doesn't care what the iTunes  
application is called. For example, if someone were to rename it  
"iTunes 7.6.2", then your version would stop working.


However, as Thomas Engelmeier pointed out in a separate message,  
Apple doesn't currently localize the names of its iApps so you're  
probably safe.



On May 24, 2008, at 12:17 PM, Mr. Gecko wrote:


because I do not need the path for what I am doing.





On May 24, 2008, at 2:05 PM, Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.


iTunesIsOpen = NO;
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSString* iTunesPath = [workspace  
absolutePathForAppBundleWithIdentifier:@"com.apple.iTunes"];

NSArray* lApplications = [workspace launchedApplications];
int lAppsCount = [lApplications count];
int a;
for (a = 0; a < lAppsCount; a++)
{
  NSDictionary* applicationD = [lApplications objectAtIndex:a];
  if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])

  {
 iTunesIsOpen = YES;
 break;
  }
}

[iTunesLMenu setTitle: NSLocalizedString(iTunesIsOpen ? @"Quit  
iTunes" : @"Launch iTunes",@"")];



On May 24, 2008, at 8:29 AM, Mr. Gecko wrote:


Thanks I am using this
iTunesIsOpen = NO;
[iTunesLMenu setTitle: NSLocalizedString(@"Launch iTunes",@"")];
NSArray *lApplications = [[NSWorkspace sharedWorkspace]  
launchedApplications];

int a;
for (a=0; a<[lApplications count]; a++) {
  NSDictionary *applicationD = [lApplications objectAtIndex:a];
  if ([[applicationD objectForKey:@"NSApplicationName"]  
isEqualToString:@"iTunes"]) {

 iTunesIsOpen = YES;
 [iTunesLMenu setTitle: NSLocalizedString(@"Quit iTunes",@"")];
  }
}
On May 23, 2008, at 5:07 PM, Nick Zitzmann wrote:


On May 23, 2008, at 4:01 PM, Mr. Gecko wrote:


How can I tell if iTunes is running with cocoa.


In this particular case, you should be able to get that  
information using -[NSWorkspace launchedApplications]...


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Jens Alfke


On 24 May '08, at 12:05 PM, Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.

...
  if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])


It would be simpler just to use the "NSApplicationBundleIdentifier"  
key, comparing it with "com.apple.iTunes".


—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: How to tell if iTunes is running.

2008-05-24 Thread Thomas Engelmeier


On 24.05.2008, at 21:05, Steve Christensen wrote:

Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.



For third party software you'd be right - Apple does not localize the  
names of iTunes / iPhoto / iDVD (browse through the *.jproj/ 
infoPlist.strings)  and AFIAK does not handle renamed or moved  
variants in their updaters, so people renamaing iApps face trouble  
anyway...


Best regards,
Tom_E
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Steve Christensen
Would something like this work better? It should deal with  
localization or if the user renames iTunes for some reason.


iTunesIsOpen = NO;
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSString* iTunesPath = [workspace  
absolutePathForAppBundleWithIdentifier:@"com.apple.iTunes"];

NSArray* lApplications = [workspace launchedApplications];
int lAppsCount = [lApplications count];
int a;
for (a = 0; a < lAppsCount; a++)
{
   NSDictionary* applicationD = [lApplications objectAtIndex:a];
   if ([[applicationD objectForKey:@"NSApplicationPath"]  
isEqualToString:iTunesPath])

   {
  iTunesIsOpen = YES;
  break;
   }
}

[iTunesLMenu setTitle: NSLocalizedString(iTunesIsOpen ? @"Quit  
iTunes" : @"Launch iTunes",@"")];



On May 24, 2008, at 8:29 AM, Mr. Gecko wrote:


Thanks I am using this
iTunesIsOpen = NO;
[iTunesLMenu setTitle: NSLocalizedString(@"Launch iTunes",@"")];
NSArray *lApplications = [[NSWorkspace sharedWorkspace]  
launchedApplications];

int a;
for (a=0; a<[lApplications count]; a++) {
   NSDictionary *applicationD = [lApplications objectAtIndex:a];
   if ([[applicationD objectForKey:@"NSApplicationName"]  
isEqualToString:@"iTunes"]) {

  iTunesIsOpen = YES;
  [iTunesLMenu setTitle: NSLocalizedString(@"Quit iTunes",@"")];
   }
}
On May 23, 2008, at 5:07 PM, Nick Zitzmann wrote:


On May 23, 2008, at 4:01 PM, Mr. Gecko wrote:


How can I tell if iTunes is running with cocoa.


In this particular case, you should be able to get that  
information using -[NSWorkspace launchedApplications]...


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-24 Thread Mr. Gecko

Thanks I am using this
iTunesIsOpen = NO;
[iTunesLMenu setTitle: NSLocalizedString(@"Launch iTunes",@"")];
NSArray *lApplications = [[NSWorkspace sharedWorkspace]  
launchedApplications];

int a;
for (a=0; a<[lApplications count]; a++) {
   NSDictionary *applicationD = [lApplications objectAtIndex:a];
   if ([[applicationD objectForKey:@"NSApplicationName"]  
isEqualToString:@"iTunes"]) {

  iTunesIsOpen = YES;
  [iTunesLMenu setTitle: NSLocalizedString(@"Quit iTunes",@"")];
   }
}
On May 23, 2008, at 5:07 PM, Nick Zitzmann wrote:



On May 23, 2008, at 4:01 PM, Mr. Gecko wrote:


How can I tell if iTunes is running with cocoa.



In this particular case, you should be able to get that information  
using -[NSWorkspace launchedApplications]...


Nick Zitzmann




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How to tell if iTunes is running.

2008-05-23 Thread Nick Zitzmann


On May 23, 2008, at 4:01 PM, Mr. Gecko wrote:


How can I tell if iTunes is running with cocoa.



In this particular case, you should be able to get that information  
using -[NSWorkspace launchedApplications]...


Nick Zitzmann


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


How to tell if iTunes is running.

2008-05-23 Thread Mr. Gecko
How can I tell if iTunes is running with cocoa. I am working on a  
program for iTunes and I am going to add a  Quit iTunes and Start  
iTunes menu.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]