• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Open CD Tray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open CD Tray


  • Subject: Re: Open CD Tray
  • From: Charles Srstka <email@hidden>
  • Date: Mon, 4 Oct 2004 19:19:49 -0500

Keep in mind that this (and the DiscRecording framework as someone else suggested) will only work if the user has a CD writer. For older Macs with only a CD-ROM or DVD-ROM drive and no CD writing capabilities (like my G4/450 and Pismo Powerbook), it will not function.

What I'm currently using is some IOKit code that I found on the carbon-development mailing list some time ago. It's not the most elegant thing in the world, since it emulates the CD eject key on the keyboard rather than manipulating the device directly. However, it's the only thing so far that I've found that works on CD-ROM devices that aren't burners. There may be a better way to do this, but since even the iTunes eject button doesn't work for drives that don't burn, it's not encouraging.

Anyway, here's what I'm currently using:

#import <IOKit/hidsystem/IOHIDLib.h>

static io_connect_t get_event_driver(void)
{
static mach_port_t sEventDrvrRef = 0;
mach_port_t masterPort, service, iter;
kern_return_t kr;

if (!sEventDrvrRef)
{
// Get master device port
kr = IOMasterPort( bootstrap_port, &masterPort );
check( KERN_SUCCESS == kr);

kr = IOServiceGetMatchingServices( masterPort, IOServiceMatching(
kIOHIDSystemClass ), &iter );
check( KERN_SUCCESS == kr);

service = IOIteratorNext( iter );
check( service );

kr = IOServiceOpen( service, mach_task_self(),
kIOHIDParamConnectType, &sEventDrvrRef );
check( KERN_SUCCESS == kr );

IOObjectRelease( service );
IOObjectRelease( iter );
}
return sEventDrvrRef;
}

static void HIDPostSysDefinedKey(const UInt8 sysKeyCode )
{
NXEventData event;
kern_return_t kr;
IOGPoint loc = { 0, 0 };

bzero(&event, sizeof(NXEventData));

event.compound.subType = sysKeyCode;
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event,
kNXEventDataVersion, 0, FALSE );
check( KERN_SUCCESS == kr );
}

@implementation NSWorkspace(TrayOpening)

- (void)openCDTray {
HIDPostSysDefinedKey(NX_SUBTYPE_EJECT_KEY);
}

@end

Charles

On Oct 4, 2004, at 7:02 PM, M. Uli Kusterer wrote:

At 17:41 Uhr -0400 04.10.2004, Adam wrote:
How can I open the CD Tray with cocoa / objective-c. I would like to recreate the functionality of the iTunes eject button.

One option, which may not be very elegant, is using the drutil command-line tool:

FILE* str = popen("drutil tray open","r");
pclose(str);

It had a man page back at MacHack, when it was used by one (look away, quick!) keynote (you can look again) speaker to great effect.
-- Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden

This email sent to email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >Open CD Tray (From: Adam <email@hidden>)
 >Re: Open CD Tray (From: "M. Uli Kusterer" <email@hidden>)

  • Prev by Date: Re: How to avoid warning with objc_msgSend
  • Next by Date: Re: How to avoid warning with objc_msgSend
  • Previous by thread: Re: Open CD Tray
  • Next by thread: Handling mouse clicks on an image
  • Index(es):
    • Date
    • Thread