Is there a way to script the ejection of CardBus (aka PCMCIA or PCCard) cards? In MacOS 9, they appeared as icons on the Desktop, and thus could be manipulated by the Finder, but not so with MacOS X.
I suppose it might be possible to do with UI scripting and the CardBus menulet, but i’m not sure about the stability of the GUI System Events app. Can menulet’s be accessed with UI scripting? Is the beta stable?
Surely there must be a UNIX CLI way to eject cards?
When you inject a PC Card, you should get a menu in the menu bar (not the Dock) indicating the card is active. If this is some sort of memory card, it should also be visible as a volume. Open a Finder window, and go to Computer and the card should be fully available as a drag & drop volume. After you are finished with it, simply drag the volume icon to the trash (the icon will be the eject icon). You can then safely eject the card. What exactly are you looking to do?
This will also work to unmount the card and make it safe to remove it:
tell application "Finder"
set the_disk to (choose from list (list disks) with prompt "Choose a volume to eject:") as string
if the_disk = "false" then return
eject disk the_disk
end tell
Thanks for the reply. No, not a memory card. Looking to eject USB and FireWire cards (neither of which show up as icons). Yes, i do get the menulet in the menu bar when a card is inserted.
The reason why i’m looking to eject the card is my Mac will sometimes crash when it goes to sleep with cards inserted; when they’re ejected, it is rock solid stable. If i can figure out how to eject ANY card in the slots, i can write a script to eject the cards immediately prior to invocation of sleep.
“Power off card” is not an option in either card’s menu. The only option enabled is “Eject Card”. The other two “options” are “Unknown Vendor” and “USB Controller” or “Firewire Controller,” depending on the card.
Tried diskutil already; no luck (but then again, these aren’t disks).
Now i might mention that when i have an HD connected via the FireWire card, the volumes mount and icons show up (as one might expect). Those volumes will dismount when ejected or their icon’s are placed in the trash (also as expected). And the FireWire card remains in the slot (also as would be expected).
But clearly there is a way to eject CardBus cards via software; after all, the PCCard menulet does it, and so did MacOS 9.
I also tried looking in /dev, but the cards don’t appear to show up there. Now these entries do show up in the system log when cards are inserted/ejected (logs trimmed to fit better on page):
IOPCCard info: cs: cb_alloc(bus 1): vendor 0x1033, device 0x0035
IOPCCard info: cs: cb_alloc(bus 1): found 3 functions
IOCardBusDevice: binding socket 0 function 0 to card services.
IOPCCard info: cs: cb_config(bus 1)
IOPCCard info: fn 0 bar 1: mem 0x90002000-0x90002fff
IOPCCard info: fn 1 bar 1: mem 0x90001000-0x90001fff
IOPCCard info: fn 2 bar 1: mem 0x90000000-0x900000ff
IOPCCard info: irq 255
IOCardBusDevice: binding socket 0 function 1 to card services.
IOCardBusDevice: binding socket 0 function 2 to card services.
IOPCCardBridge: bad range 2(90002000:00001000)
IOPCCardBridge: bad range 2(90001000:00001000)
IOPCCardBridge: bad range 2(90000000:00000100)
USBF: 596069.993 [0x21e7200] USB Generic Hub @ 1 (0x0)
USBF: 596070. 31 [0x2bfc600] USB Generic Hub @ 1 (0x0)
USBF: 596070.325 IOUSBHIDDriver[0x2c38a00]::start - USB HID Device @ 2 (0x1100000)
IOPCCard info: cs: cb_free(bus 1)
IOPCCard: shutting down socket 0.
IOPCCard: calling terminate on socket 0 function 2 nub 0x2d6fe00.
IOCardBusDevice: releasing socket 0 function 2 from card services.
IOPCCard: calling terminate on socket 0 function 1 nub 0x2d8b000.
IOCardBusDevice: releasing socket 0 function 1 from card services.
IOPCCard: calling terminate on socket 0 function 0 nub 0x23cec00.
IOCardBusDevice: releasing socket 0 function 0 from card services.
Anyone ever figure this out? I use a Lexar 32-bit CF adapter in my PowerBook and simply unmounting the CF card’s volume is not enough. I have to power off the PC card from the menulet, too. If I for get and don’t do both, I’ll frequently get a kernel panic.
Looking for a way to script powering off the pc card…
Model: Aluminum Powerbook G4
Browser: Safari 417.8
Operating System: Mac OS X (10.4)
I found a script elsewhere that was supposed to interact with the clock menu extra and change a setting. I adapted it to my particular need, but it still doesn’t work. Seems to always want to choose menu item 4 no matter how I modify the script. My PC Card menu extra is menu 1 of SystemUIServer right now.
tell application "System Events"
tell process "SystemUIServer"
tell menu bar 1
get every menu bar item where value of attribute "AXDescription" of it is "PC Card menu extra"
set PCCardMenuBarItem to first item of result
tell PCCardMenuBarItem
click -- open menu
try
click menu item "Power off Card" of menu 1
on error
tell current application to display dialog "Could not set the PC card menu extra to \"Power off Card\"" buttons {"OK"} default button "OK"
end try
end tell
end tell
end tell
end tell