I've been working on an application that users might want to add to their login items ... so how do we do that in Lazarus?
Even better: how do we detect if it's already there, and how do we remove it if the user wants it removed as well?
Based on info I found (see this forum post), an example code how you could implement this in your application (please add "Process" to your uses clause);
View: Is your App already in the Login Items?
function CheckLoginItem:Boolean;
var s:ansistring;
begin
RunCommand('/usr/bin/osascript', ['-e','tell application "System Events" to get the name of every login item'],s);
CheckLoginItem := (Pos('YourAppName',s)>0);
end;
Add our app to the login items:
procedure AddLoginItem;
var s:ansistring;
appName:string;
begin
appName := Copy(Application.ExeName,0,pos('.app/',Application.ExeName)+3);
RunCommand('/usr/bin/osascript', ['-e','tell app "System Events" to make login item at end with properties {path:"'+appName+'", hidden:true}'],s);
end;
Remove your app from the login items:
procedure RemoveLoginItem;
var s:ansistring;
begin
RunCommand('/usr/bin/osascript', ['-e','tell app "System Events" to delete login item "YourAppName"'],s);
end;