Tuesday 15 January 2013

osx - How to make Xamarin.Mac app "Open at Login"? -


I have the Xamarin.Mac app that needs to open automatically on login. How can I get this app without having to click on it manually?

open on login in screenshot UI

I can give you an indication of how to program it. / P>

For this approach you need to use call to native libraries via code

After code you get an idea to proceed How to give:.

  // Required Library const string DllName = "/System/Library/Frameworks/Application.Services.framework/ApplicationServices"; Fixed LSSharedFileList () {dllHandle = Dlfcn.dlopen (DllName, 0); KLSSharedFileListSessionLoginItems = Dlfcn.GetStringConstant (dllHandle, "kLSSharedFileListSessionLoginItems"); KLSSharedFileListItemLast = Dlfcn.GetStringConstant (dllHandle, "kLSSharedFileListItemLast"); } [DllImport (DllName)] Public static deportation IntPtr LSSharedFileListCreate (IntPtr inAllocator, IntPtr inListType, IntPtr listOptions); [DllImport (DllName, CharSet = CharSet.Unicode)] Public Static Extern Zero CFRelease (IntPtr CF); [DllImport] Public Reclamation Static IntPtr LSSharedFileListInsertItemURL (IntPtr inList, IntPtr insertAfterThisItem, IntPtr inDisplayName, IntPtr inIconRef, IntPtr inurl, IntPtr inPropertiesToSet, IntPtr inPropertiesToClear);   

And here's the real piece:

  public static void EnableLogInItem () {IntPtr pFileList = IntPtr.Zero; IntPtr pItem = IntPtr.Zero; Try {pFileList = LSSharedFileListCreate (IntPtr.Zero, kLSSharedFileListSessionLoginItems, IntPtr.Zero); PItem = LSSharedFileListInsertItemURL (pFileList, kLSSharedFileListItemLast, IntPtr.Zero, IntPtr.Zero, NSBundle.MainBundle.BundleUrl.Handle, IntPtr.Zero, IntPtr.Zero); } Finally {CIFR (PITM); CFR (Pipelist); }}   

Please note that this is not a complete solution, it is only a snippet to place an app in the login items list. Of course you have to handle the errors, after each call, you should check the intact. Zero, but this should know how it works.

Hope that helps!

No comments:

Post a Comment