Search code examples
macosshellterminalcopyapplescript

Duplicate File Using Applescript/Terminal


I am writing a program using applescript that will compile a separate application using the "osacompile" terminal command and then duplicate a file that is found within the package contents of the original file (not the one created via osacompile) to the package contents of the osacompiled application. However, I cannot even manage to move the selected file to the desktop or the documents folder.

I've tried several ways such as the "cp" command and the "tell application Finder" command. In the broken script sample pasted below, I tried to use the "cp" command.

Here is the script:

set MusicFile to (path to me) & "Contents:Resources:CountryPackages:Soviet Union:SovietMusic.mp3"

set SovietUnion to "display dialog \"ok\""

set DesktopPath to (path to desktop)

do shell script "osacompile -x -o ~/Desktop/SovietUnion.app -e " & quoted form of SovietUnion

set DuplicateDestination to (path to desktop as alias) & "SovietUnion.app:Contents:Resources:"      

do shell script "cp -RfXv " & MusicFile & DesktopPath

Solution

  • Some paths doesn't look right. Inside the shell script you are supposed to use UNIX paths.

    set MusicFile to ((path to me) as text) & "Contents:Resources:CountryPackages:Soviet Union:SovietMusic.mp3"
    
    set DuplicateDestination to alias (((path to desktop) as text) & "SovietUnion.app:Contents:Resources:")  
    
    do shell script "cp -RfXv " & quoted form of POSIX path of MusicFile & space & quoted form of POSIX path of DesktopPath