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.
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"
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
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"