It is currently Sat Oct 31, 2020 9:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Copy .app to applications folder
PostPosted: Thu Jun 11, 2020 1:07 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
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:
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

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Thu Jun 11, 2020 3:58 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 587
This works for me:
Code:
CopyFile(GetCurrentDirectory() + "prog.app", "/Applications/prog.app")

The actual Applications folder seems to be /Applications, not /Username/Applications.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Thu Jun 11, 2020 4:54 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
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

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Thu Jun 11, 2020 7:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 587
Oh, sorry. I should have tested it further.

Try RenameFile. It worked for me.
Code:
RenameFile(GetCurrentDirectory() + "prog.app", "/Applications/prog.app")


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Fri Jun 12, 2020 6:18 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
Lovely works out of the box.

Fails when source does not exist (In docs)

Also fails if destination exists.

But great.

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Fri Jun 12, 2020 7:31 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
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?

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Fri Jun 12, 2020 7:53 am 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 948
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).

:wink:

_________________
(English is not my native language, I use an online translator.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Fri Jun 12, 2020 2:48 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
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

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Wed Sep 16, 2020 3:53 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
Hi All

Ok got the copy bit working but I am still deleting the original in the applications folder.

Copying using this code.

Code:
 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

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Copy .app to applications folder
PostPosted: Wed Sep 16, 2020 4:14 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1131
Location: Portugal
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:
  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.

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye