Copying files with do shell script

Hi,

I need to copy files using the do shell script command, and for portability I have located these files in the Application bundle (so far so good), however the do shell script command working directory is “/” how do I locate the App bundle in order to copy the correct files to their respective locations on the target machine?

I could just search for the App in question and then pass that into another shell script, but this seems a little inelegant.

Thanks

Hi

try this


set myAppBundle to path to me as text
do shell script "/bin/cp " & quoted form of (POSIX path of myAppBundle & "Contents/Resources/myFile.ext") & space & quoted form of "/path/to/destination/myFile.ext"

Or alternatively without shell scripts:

tell application "Finder"
duplicate file (CopyFile) to folder (TestFolder)
end tell

or…

set myAppFile to (resource path of main bundle) & "/myFile.ext"
set theDestFile to "/path/to/destination/myFile.ext"
do shell script "ditto -rsrc " & quoted form of myAppFile & space & theDestFile 

BTW, the difference will be that

tell application "Finder"

may produce an sound that could be unwanted. That’s the reason I’m using “shell script”.

BTW2, if you need to make silent replace you should add “-f” option, like this:

set myAppBundle to path to me as text
do shell script "/bin/cp -f" & quoted form of (POSIX path of myAppBundle & "Contents/Resources/myFile.ext") & space & quoted form of "/path/to/destination/myFile.ext"

Oops, I’ve just found that “-f” switch of “cp” copies file only if it already exists. Can’t figure how to just make silent overwriting… :expressionless: