public int openDocProc(int theAppleEvent, int reply, int handlerRefcon) { if(!this.isEnabled()){ return OS.noErr; } AEDesc aeDesc = new AEDesc(); EventRecord eventRecord = new EventRecord(); OS.ConvertEventRefToEventRecord(theAppleEvent, eventRecord); try { int result = OpenDocJNI.AEGetParamDesc(theAppleEvent,OS.kEventParamDirectObject, typeAEList, aeDesc); if (result != OS.noErr) { System.err.println("OSX: Could call AEGetParamDesc. Error: " + result); return OS.noErr; } } catch (java.lang.UnsatisfiedLinkError e) { System.err.println("OSX: AEGetParamDesc not available. Can't open sent file"); return OS.noErr; } int[] count = new int[1]; OS.AECountItems(aeDesc, count); if (count[0] > 0) { String[] fileNames = new String[count[0]]; int maximumSize = 80; // size of FSRef int dataPtr = OS.NewPtr(maximumSize); int[] aeKeyword = new int[1]; int[] typeCode = new int[1]; int[] actualSize = new int[1]; for (int i = 0; i < count[0]; i++) { if (OS.AEGetNthPtr(aeDesc, i + 1, OS.typeFSRef, aeKeyword,typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) { byte[] fsRef = new byte[actualSize[0]]; C.memmove(fsRef, dataPtr, actualSize[0]); int dirUrl = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault, fsRef); int dirString = OS.CFURLCopyFileSystemPath(dirUrl,OS.kCFURLPOSIXPathStyle); OS.CFRelease(dirUrl); int length = OS.CFStringGetLength(dirString); char[] buffer = new char[length]; CFRange range = new CFRange(); range.length = length; OS.CFStringGetCharacters(dirString, range, buffer); OS.CFRelease(dirString); fileNames[i] = new String(buffer); } if (OS.AEGetNthPtr(aeDesc, i + 1, typeText, aeKeyword,typeCode, dataPtr, maximumSize, actualSize) == OS.noErr) { byte[] urlRef = new byte[actualSize[0]]; C.memmove(urlRef, dataPtr, actualSize[0]); fileNames[i] = new String(urlRef); } } if( fileNames.length > 0 ){ OpenDocAction.saveAndOpen( fileNames[0] ); } } return OS.noErr; }