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.
OpenElec The ultimate XBMC distribution. No operating system required, comes completely in a compact form with Embedded Linux, for Intel, AMD, AppleTV, Raspberry Pi, etc.
Burn Small, free, and super powerful tool for burning CD's and DVD's (audio, video,data).
Lazarus / FPC Lazarus / Free Pascal Compiler - A cross platform software development environment that show similarities with the good old Delphi.
Lubuntu A Ubuntu variant aimed at being small and fast. Love it!
IcoMoon Ultimate place to create your own icon fonts, with existing icons and/or your own designs, for your computer or webpage, ... for free.
Elementary OS (Freya) Freya, a.k.a. Elementary OS, is my favorite Linux distribution. It looks slick and works great. Highly recommend it.
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
RenameMyTVSeries-2.3.15-Windows-x64-setup.exeDate: 2025-12-14 - Size: 49.1 MBRename My TV Series, for Windows (Intel 64 bit), a tool to assist in renaming TV Show episode files. Static builds of ffmpeg and ffprobe are included.
squirclenomore-v1.0.2-macos.dmgDate: 2025-11-29 - Size: 5.5 MBmacOS Tahoe applies a very ugly Squircle jail to application icons - SquircleNoMore removes these and resets the normal application icon.
RenameMyTVSeries-2.3.12-GTK-Linux-x64-static-ffmpeg.tar.xzDate: 2025-10-06 - Size: 78.3 MBRename My TV Series, for Linux (64 bit GTK), a tool to assist in renaming TV Show episode files. This bundle comes with (large) static builds of ffmpeg and ffprobe.
RenameMyTVSeries-2.3.12-QT5-Linux-x64-static-ffmpeg.tar.xzDate: 2025-09-28 - Size: 78.3 MBRename My TV Series, for Linux (64 bit QT5), a tool to assist in renaming TV Show episode files. This bundle comews with rather large static builds of ffmpeg and ffprobe.
RenameMyTVSeries-2.3.12-QT5-Linux-x64-shared-ffmpeg.tar.xzDate: 2025-09-28 - Size: 1.9 MBRename My TV Series, for Linux (64 bit QT5), a tool to assist in renaming TV Show episode files. This bundle relies on ffmpeg and ffprobe shared libraries on your system.
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).