Forum > macOS / Mac OS X

[Solved] How add login items (using SMAppService, macOS 13+)

(1/2) > >>

Hansaplast:
Trying to work with the new SMAppService option to add my application to the Login-Items for an App Store test project and find myself in need for the support for the macOS 13 SDK (this new approach has been made available since macOS 13).


Does anyone know where I can find the appropriate files or how to build these myself?
So far I have only found the proper Free Pascal files for macOS 11 and wasn't able to find anything in this forum.

Hansaplast:
I've tried several conversion tools including ObjCParser.
However, I'm not sure what to do with the result (an .inc file), not to mention that the code seems not entirely complete and the tool not supporting ObjC 2. Another tool, OctDroid, seems to do a good job for Delphi, but is of course not very usefull for Lazarus (please correct me if I'm wrong).


Does anyone know what tool was used for SDK 10?
Do I need to use ObjCParser for the entire SDK?

cdbc:
Hi

--- Quote ---OctDroid, seems to do a good job for Delphi, but is of course not very usefull for Lazarus
--- End quote ---
Hmmm... Why the h*ll not?!?
Regardless of which tool you might use, you still (always) have to have human supervision, with the process!
NO automated tool, that I know of, will perform perfect on everything you might throw at it...
So - If you have to do a couple of minor adjustments of the code, to go from 'Delphi' to 'Lazarus', what would it matter, as long as you get the job done?
Just my 2 cent's worth.
Regards Benny

Hansaplast:
Thanks for replying Benny!


I'm sure you're right, but my knowledge is somewhat limited on the topic. Especially on the topic of Delphi 😞
Code looks very different than all the other includes/units I have seen.


Example (not expecting anyone to do the work for me);



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Macapi.ServiceManagement;  {$MODE Delphi}{$modeswitch objectivec1}  interface  uses  Macapi.ObjectiveC, Macapi.CoreFoundation, Macapi.CocoaTypes, Macapi.Foundation, Macapi.Security;  const  { TODO : Macro probably use invalid symbol "kSMRightBlessPrivilegedHelper": }  (* kSMRightBlessPrivilegedHelper "com.apple.ServiceManagement.blesshelper" *)  { TODO : Macro probably use invalid symbol "kSMRightModifySystemDaemons": }  (* kSMRightModifySystemDaemons "com.apple.ServiceManagement.daemons.modify" *)  kSMErrorInternalFailure = 2;  kSMErrorInvalidSignature = 3;  kSMErrorAuthorizationFailure = 4;  kSMErrorToolNotValid = 5;  kSMErrorJobNotFound = 6;  kSMErrorServiceUnavailable = 7;  kSMErrorJobPlistNotFound = 8;  kSMErrorJobMustBeEnabled = 9;  kSMErrorInvalidPlist = 10;  kSMErrorLaunchDeniedByUser = 11;  kSMErrorAlreadyRegistered = 12;  SMAppServiceStatusNotRegistered = 0;  SMAppServiceStatusEnabled = 1;  SMAppServiceStatusRequiresApproval = 2;  SMAppServiceStatusNotFound = 3;  type  SMAppService = interface;    SMAppServiceStatus = NSInteger;  TSMAppServiceBlockMethod1 = procedure(error: NSError) of object;    SMAppServiceClass = objcclass(NSObject)  SMAppServiceClass = interface(NSObjectClass)    ['{A4BDE3B3-3167-43B5-A5B3-4D441AFC9FC4}']    {class} function agentServiceWithPlistName(plistName: NSString): Pointer; cdecl;    {class} function daemonServiceWithPlistName(plistName: NSString): Pointer; cdecl;    {class} function loginItemServiceWithIdentifier(identifier: NSString): Pointer; cdecl;    {class} function mainAppService: SMAppService; cdecl;    {class} procedure openSystemSettingsLoginItems; cdecl;    {class} function statusForLegacyURL(url: NSURL): SMAppServiceStatus; cdecl;  end;    SMAppService = interface(NSObject)    ['{997656A2-2E6A-4BAE-B2F3-248CD99993AD}']    function registerAndReturnError(error: PPointer): Boolean; cdecl;    function status: SMAppServiceStatus; cdecl;    function unregisterAndReturnError(error: PPointer): Boolean; cdecl;    procedure unregisterWithCompletionHandler(handler: TSMAppServiceBlockMethod1); cdecl;  end;  TSMAppService = class(TOCGenericImport<SMAppServiceClass, SMAppService>) end;  const  libServiceManagement = '/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement';  function SMLoginItemSetEnabled(identifier: CFStringRef; enabled: Boolean): Boolean; cdecl;  external libServiceManagement name _PU + 'SMLoginItemSetEnabled';  function SMJobCopyDictionary(domain: CFStringRef; jobLabel: CFStringRef): CFDictionaryRef; cdecl;  external libServiceManagement name _PU + 'SMJobCopyDictionary';  function SMCopyAllJobDictionaries(domain: CFStringRef): CFArrayRef; cdecl;  external libServiceManagement name _PU + 'SMCopyAllJobDictionaries';  function SMJobSubmit(domain: CFStringRef; job: CFDictionaryRef; auth: AuthorizationRef; outError: PCFErrorRef): Boolean; cdecl;  external libServiceManagement name _PU + 'SMJobSubmit';  function SMJobRemove(domain: CFStringRef; jobLabel: CFStringRef; auth: AuthorizationRef; wait: Boolean; outError: PCFErrorRef): Boolean; cdecl;  external libServiceManagement name _PU + 'SMJobRemove';  function SMJobBless(domain: CFStringRef; executableLabel: CFStringRef; auth: AuthorizationRef; outError: PCFErrorRef): Boolean; cdecl;  external libServiceManagement name _PU + 'SMJobBless';  implementation  uses  System.SysUtils;  var  ServiceManagementModule: THandle;  initialization  ServiceManagementModule := LoadLibrary(libServiceManagement);  finalization  if ServiceManagementModule <> 0 then    FreeLibrary(ServiceManagementModule);  end.

cdbc:
Hi
Hmmm...
Ok, so first order of business, is to figure out if we(laz) have an equivalent /library/ to 'Delphi's 'Macapi'?!? If not we might have to create such a beast ourselves :(  But, humans made it for 'Delphi', so humans can create one for 'Lazarus'  8)
Is that library to be found anywhere?!? just to have a looksee of what it does...
The rest of the file, deals mostly with the interfaces used by Apple.
Regards Benny

Navigation

[0] Message Index

[#] Next page

Go to full version