Page 1 of 1
Copy .app to applications folder
Posted: Thu Jun 11, 2020 1:07 pm
by collectordave
Driving me nuts.
Is it possible to copy a .app file into the applications folder?
and then run that application.
I have tried the following to copy but it fails!
Code: Select all
Sourcefile.s = GetUserDirectory(#PB_Directory_Documents) + "Temp/My New.app"
DestinationFile.s = GetUserDirectory(#PB_Directory_Programs) + "My New.app"
NSFM = CocoaMessage(0, 0, "NSFileManager defaultManager")
CocoaMessage(0, NSFM, "copyItemAtPath:$", @sourceFile, "toPath:$", @destinationFile, "error:", #nil)
I can do it with terminal commands
cd /Applications
cp -r /Users/MyName/Documents/Temp/MyNew.app MyNew.app
But using filberts AppleScript how do I combine the two commands?
I add Do Shell Script to each to no avail.
CD
Re: Copy .app to applications folder
Posted: Thu Jun 11, 2020 3:58 pm
by wombats
This works for me:
Code: Select all
CopyFile(GetCurrentDirectory() + "prog.app", "/Applications/prog.app")
The actual Applications folder seems to be /Applications, not /Username/Applications.
Re: Copy .app to applications folder
Posted: Thu Jun 11, 2020 4:54 pm
by collectordave
Unfortunately that copies the .app file but not the content of the file.
I am having some success doing a recursive copy of the content.
Just cannot set the icon for the file just yet.
Cheers
CD
Re: Copy .app to applications folder
Posted: Thu Jun 11, 2020 7:56 pm
by wombats
Oh, sorry. I should have tested it further.
Try RenameFile. It worked for me.
Code: Select all
RenameFile(GetCurrentDirectory() + "prog.app", "/Applications/prog.app")
Re: Copy .app to applications folder
Posted: Fri Jun 12, 2020 6:18 am
by collectordave
Lovely works out of the box.
Fails when source does not exist (In docs)
Also fails if destination exists.
But great.
CD
Re: Copy .app to applications folder
Posted: Fri Jun 12, 2020 7:31 am
by collectordave
Having problems deleting the app.
DeleteFile and DeleteDirectory do not work
So I do the following
First I move the app from applications to a temporary folder and convert to a normal folder
DestinationaFile.s = "/Applications/MyNew.app"
Debug "Make Back File" ;Removes app from /Applications and converts to folder
RenameFile(DestinationaFile,GetUserDirectory(#PB_Directory_Documents) + "Temp/MyNew")
This works but DeleteDirectory() still does not work
MyFolder.s = GetUserDirectory(#PB_Directory_Documents) + "Temp/MyNew"
;Delete the actual executable
Debug DeleteFile(MyFolder + "/Contents/MacOS/MyNew", #PB_FileSystem_Force)
;Delete the MacOS folder
Debug DeleteDirectory(MyFolder + "/Contents/MacOS", "*.*", #PB_FileSystem_Recursive|#PB_FileSystem_Force)
;Delete the Contents folder
Debug DeleteDirectory(MyFolder + "/Contents", "*.*", #PB_FileSystem_Recursive|#PB_FileSystem_Force)
;Does not work on its own needs the above three statements
Debug DeleteDirectory(MyFolder,"")
This then deletes the whole thing.
I do use recursive and force etc.
I can only assume it is something to do with permissions on individual files in the folder?
Re: Copy .app to applications folder
Posted: Fri Jun 12, 2020 7:53 am
by Marc56us
Regardless of the operating system, there are several conditions to be able to delete a directory.
1. Not to be there nor in one of its sub-directories (so under PB do a SetCurrentDirectory(<elsewhere> before)
2. That there are no files left open in any of these directories by any other program.
3. Have sufficient permissions (remember that in a unix-based system, you need +x permissions to browse a directory).

Re: Copy .app to applications folder
Posted: Fri Jun 12, 2020 2:48 pm
by collectordave
Hi Marc56us
1. Definitely in a different folder but tried setcurrentdirectory as well still the same.
2. No files in use by any other programme
3. Permissions checked the folder was created by the programme and can be deleted using finder no problem no passwords asked for.
CD
Re: Copy .app to applications folder
Posted: Wed Sep 16, 2020 3:53 pm
by collectordave
Hi All
Ok got the copy bit working but I am still deleting the original in the applications folder.
Copying using this code.
Code: Select all
NSFM = CocoaMessage(0, 0, "NSFileManager defaultManager")
destinationFile.s = "/Applications/World Stamp Collector(Mac).app"
sourceFile.s = "/Volumes/World Stamp Collector/World Stamp Collector(Mac).app"
CocoaMessage(0, NSFM, "copyItemAtPath:$", @sourceFile, "toPath:$", @destinationFile, "error:", #nil)
Is there an NSFileManager command to overwrite the original so I do not have to copy it out and then delete?
Regards
CD
Re: Copy .app to applications folder
Posted: Wed Sep 16, 2020 4:14 pm
by collectordave
Just a dim moment.
What I am trying to do is replace the application installed originally with an updated version downloaded from the internet.
Once changed replace to Remove and then copy new one I looked again.
Code: Select all
NSFM = CocoaMessage(0, 0, "NSFileManager defaultManager")
destinationFile.s = "/Applications/World Stamp Collector(Mac).app"
sourceFile.s = "/Volumes/World Stamp Collector/World Stamp Collector(Mac).app"
If ExamineDirectory(#PB_Any,destinationFile,"*.*") <> 0
;Delete Existing Application
CocoaMessage(0, NSFM, "removeItemAtPath:$", @destinationFile, "error:", #nil)
EndIf
;Now Copy The new application
CocoaMessage(0, NSFM, "copyItemAtPath:$", @sourceFile, "toPath:$", @destinationFile, "error:", #nil)
I simply download the DMG file
mount it
run this then detach the dmg
Works quick and easy now.
Sorry to bother everyone.