Page 1 of 1
Forum

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!



Share:
Notifications
Clear all

[Solved] Lazarus - MacOS X - How to restart your own application from within itself

1 Posts
1 Users
0 Reactions
2,160 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

For those who have read the "How to get Retina working" post, you might have noticed the complications you're running into, as you cannot set the needed Retina value from within your program. It will only be effective after you restart the program.

To do this, the following function that I found at the Lazarus Forum, with a small modification to make it work under MacOS X, works well.

First make sure "Process" is included in your Uses clause.

Then define the "Restart()" procedure, which you can call at any time you'd like. Be careful to not end up in an endless loop though.

procedure Restart;
VAR aProcess : TProcess; //TProcess is crossplatform is best way
begin
  aProcess := TProcess.Create(nil);
  aProcess.CommandLine := '"'+Application.ExeName+'"';
  aProcess.Execute;
  aProcess.Free;
  Application.Terminate;
end;

Mac specific for Retina:

What I did, sloppy or not, is add the following to the "OnCreate()" event of the main form:

procedure TForm1.FormCreate(Sender: TObject);
var s:AnsiString;
begin
  // Retina, requires a restart to become effective. // First we read if the AppleMagnifiedMode is set or not
  RunCommand('/usr/bin/defaults',['read','com.yourcompany.yourapp','AppleMagnifiedMode'],s); // If set, it returns "Yes" (or possibly 1 or True - no guarantees here)
  s:=Uppercase(s);
  if (Pos('YES',s)>0) or (Pos('TRUE',s)>0) or (s='1') or (s='') then
    begin
      RunCommand('/usr/bin/defaults',['write','com.yourcompany.yourapp','AppleMagnifiedMode','NO'],s);
      Restart;
    end;    
...               

What we do here: check if AppleMagnifiedMode is activated. If activated, deactivate it and restart.


   
ReplyQuote
Share: