Replacing mac app from "Applications" other mac application

We have a desktop application, which has upgrade utility which updates the main application i.e it downloads latest build from SFTP and then replaces it with the build present on the machine. In windows it is updated properly. But on mac the main desktop application is not being replaced. It is present in Applications.
Is it possible to delete/replace desktop app from “Applications” on Mac machine using other desktop application in MacOS?
If it can be done then how to do that?

Thank you

What is your code? Do you get error messages?

You may have to use sudo/elevated privileges if you change the application folder on the Mac.

take a look at the Kaju self updater project, open source search for it on the forum.
this update is done with a command line, different on each platform.

If you are installing in the usual places (Program Files on MS-Windows and Applications on Mac) then chances are you will need to elevate privileges to perform the update.

If you want the updated application to automatically launch afterwards this adds another complication because your elevated helper application will cause your main application to run elevated. From a security point of view this should not be done.

We do the following method:

  1. Main App
    • Main app launches update helper app 1 with elevated privileges.
    •. Main app confirms that helper app 1 has launched and then launches update helper app 2 without elevated privileges.
    •. Main app confirms that helper app 2 has launched and then exits.

  2. Helper app 1
    • Helper app 1 waits until main app has quit.
    • Helper app 1 replaces the files.
    • Helper app 1 quits.

  3. Helper app 2
    • Helper app 2 waits for helper app 1 to quit.
    • Helper app 2 launches updated main app.

Communication between the apps is done via mutexes and text files.

[quote]We do the following method:

  1. Main App
    • Main app launches update helper app 1 with elevated privileges.
    •. Main app confirms that helper app 1 has launched and then launches update helper app 2 without elevated privileges.
    •. Main app confirms that helper app 2 has launched and then exits.

  2. Helper app 1
    • Helper app 1 waits until main app has quit.
    • Helper app 1 replaces the files.
    • Helper app 1 quits.

  3. Helper app 2
    • Helper app 2 waits for helper app 1 to quit.
    • Helper app 2 launches updated main app.[/quote]

we are doing some what same process but there is only Main app and Helper app 1.
From helper app1, main application is replaced and is launched and then it quits.
This is working in Windows but not for mac. the application is not replacing. Do not get any error as well when deleting the main app

Please can you explain how to do that

If you have the MBS plugins then AuthorizationMBS can do it. I think the macoslib project might have an implementation of the Mac OS API AuthorizeAndExecute which is probably what AuthorizationMBS is using. Both solutions also handle prompting for the details of an admin user.

Please note, that if you are only using one helper app then you will be re-launching the application with root privileges and not as the user who originally launched the app. Apart from this being bad for security it could mean that your app does not find user specific folders. This applies for both Mac & MS-Windows.

Create an Apple installer, is it is allowed to do what you want.

I didn’t understand what you are trying to say.

Sam means a pkg file. Sam’s AppWrapper can do such a pkg file. You can do it with the command line - somehow (found https://www.techrepublic.com/article/pro-tip-use-terminal-to-create-packages-for-software-deployment/ by goggling). Last time I checked there was an app out there to create packages. Here it is: http://s.sudre.free.fr/Software/Packages/about.html . I never managed to get the permissions correct. Sam’s AppWrapper should be the easiest solution.

You mean to download and install package when updating…?
For installation we are creating package to install on Mac

@devyani gaikwad : pretty please - you need to give us a bit more information about what you do. And where exactly you have a problem. If you already do an installer where exactly did you have the original problem? Please describe what you did, what you tried and what didn’t work.

To install on Mac we have created package which has main app as well as helper app(this app is used to update/replace the main application)
So what happening is when helper app is executed it downloads the updated build of main from ftp and delete the main app present in applications and then copy it latest build in applications and then launch it.
Now what is happening is on Mac machine the main is neither delete nor it is being replaced.
I have not tried anything other than this yet.

Okay. So show us your code for deleting. It’s possible that you need elevated privileges for this, too.

It just simply

dim f as folderitem F=specialfolder.applications.child("abc.app") F.delete

Have you tried this on an app on macOS? It does nothing. You need to delete file by file. Below is my routine for deleting a folder which is the same as an app on the Mac. It doesn’t have the check for the folder size (cause some special customers wrote their data into the application folder). Also you need to do a final check before the privileges are elevated and the app is deleted with a shell script.

[code]Private Function DeleteEntireFolder(theFolder as FolderItem, continueIfErrors as Boolean = false) as Integer

// Returns an error code if it fails, or zero if the folder was deleted successfully

dim returnCode, lastErr, itemCount as integer
dim files(), dirs() as FolderItem

if theFolder = nil or not theFolder.Exists() then
return 0
end if

// Collect the folder‘s contents first.
// This is faster than collecting them in reverse order and deleting them right away!
itemCount = theFolder.Count
for i as integer = 1 to itemCount
dim f as FolderItem
f = theFolder.TrueItem( i )
if f <> nil then
if f.Directory then
dirs.Append f
else
files.Append f
end if
end if
next

// Now delete the files
for each f as FolderItem in files
f.Delete
lastErr = f.LastErrorCode // Check if an error occurred
if lastErr <> 0 then
if continueIfErrors then
if returnCode = 0 then returnCode = lastErr
else
// Return the error code if any. This will cancel the deletion.
return lastErr
end if
end if
next

redim files(-1) // free the memory used by the files array before we enter recursion

// Now delete the directories
for each f as FolderItem in dirs
lastErr = DeleteEntireFolder( f, continueIfErrors )
if lastErr <> 0 then
if continueIfErrors then
if returnCode = 0 then returnCode = lastErr
else
// Return the error code if any. This will cancel the deletion.
return lastErr
end if
end if
next

if returnCode = 0 then
// We‘re done without error, so the folder should be empty and we can delete it.
theFolder.Delete
returnCode = theFolder.LastErrorCode
end if

return returnCode

exception exc
theException = new ErrorException(exc, currentMethodName)
End Function
[/code]

Thanks @Beatrix Willius I will try this and let you know.
Thank you

We use the Apple installer packages for updates to our applications, as they will replace the older version of the application whereever it’s installed. You don’t need to delete the existing application first, however you do need to quit it.

Once our application has confirmed with the user first that they want to update; we then download the update (using the main application). Once the download has finished we verify it to make sure that it’s actually the update we’re expecting (and not a drive-by). Then we launch the update and quit the application.

When you launch the update, the user is presented with the Apple installer, and they follow the directions.