Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
As of macOS 13, Apple introduced SMAppService as a replacement for SMLoginItemSetEnabled. Figuring out how this works was very confusing with the contradicting information I ran into - probably due to the difference between starting an application and starting a service or daemon.
Anywho, long story short, it took me a ton of work to finally figure it out. Special thanks to The Eskimo in the Apple Developer forum who quick and concise showed me how to use SMAppService properly. Without his help I'd still be bumbling around trying to figure it out.
So what I want to do: Have the ability to add my application, distributed through the App Store, to the Login Items.
For this I'll use SMAppService by calling 3 basic functions:
These 3 functions can be called within your application, and there is no need to create a helper tool for this. We do however need a link to the headers of macOS 13 (or newer) since Lazarus is still shipping with links to the macOS 10.10 SDK (if I'm recalling that correctly). Took me a lot of time and effort, but I got it to work (Lazarus /FPC can be quite the miracle if you as ask me(.
I created this unit, ServiceManagementAppService.pas (feel free to name it something else), basically only looking at the 3 functions I need for now:
unit ServiceManagementAppService;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$linkframework ServiceManagement}
interface
uses Classes, SysUtils, CocoaAll;
const
SMAppServiceStatusNotRegistered =0;
SMAppServiceStatusEnabled =1;
SMAppServiceStatusRequiresApproval =2;
SMAppServiceStatusNotFound =3;
SmAppServiceStatusResult :
Array [0..3] of string =
('Not registered',
'Enabled',
'Requires Approval',
'Not found' );
type
SMAppServiceStatus = NSInteger;
type
SMAppService = objcclass external (NSObject)
public
function registerAndReturnError(error: NSErrorPtr): objcbool; message 'registerAndReturnError:';
function unregisterAndReturnError(error: NSErrorPtr): objcbool; message 'unregisterAndReturnError:';
function status:SMAppServiceStatus; message 'status';
end;
implementation
end.
Now include this unit in your application's uses clause of course and you can call register, unregister and status as showns in these example calls:
var
appService: SMAppService;
StatusReturn : SMAppServiceStatus;
Registered:boolean;
UnRegistered:boolean;
begin
try
// Create a service
appService := SMAppService.new;
// Resgister service
Registered := appService.registerAndReturnError(nil);
// Unregister service
UnRegistered := appService.unregisterAndReturnError(nil);
// Get current status
// StatusReturn:
// SMAppServiceStatusNotFound - your app was never registered as login item
// SMAppServiceStatusEnabled - your app is registered as a login item
// SMAppServiceStatusNotRegistered - your app is registered as a login item
StatusReturn := appService.status;
except
Showmessage('fail');
end;
end;
Caution: as I understand, per Apple guidelines, your app is not allowed to just add itself to the Login items without user interaction. So handle this call with care,
Note: Not sure if it is required, but I did compile with the '-WM13.0' compiler (Lazarus -> Project -> Options -> Compiler Options -> Custom Options) - not sure if this is a requirement.
Burn Small, free, and super powerful tool for burning CD's and DVD's (audio, video,data).
IINA VideoPlayer One of the best media players for MacOS X - it's free and a great alternative for, and more stable than, VLC.
Lubuntu A Ubuntu variant aimed at being small and fast. Love it!
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).