cp command in do shell script not working. Newbie needs help


Ive never used applescript nor really programed so forgive the ignorance.

I need to create a droplet that will take a text file with a path to a file on a nfs share in it, mount the share, copy the file to the users desktop and then unmount the ifs share.

For example, the text file may contain “/path/to/nfsshare/object_to_be_downloaded”

Here is the code I have patched together from several sources (this the actual path information anonymized)

on open Path_File
set UserName to system attribute “USER”
set desktopPath to “/Users/” & UserName & “/Desktop/”
tell application “Finder” to mount volume “nfs://nfsshare/path/”
open for access Path_File
set pathVariable to (read Path_File)
close access Path_File
set FileSource to “/Volumes/nfsshare” & pathVariable
do shell script "cp " & FileSource & desktopPath
end open

When I drop the test file into the droplet I get an error about the usage of cp that follows:
sh: line 1: /Users/user/Desktop/: is a directory

Any idea what I am doing wrong?

Model: iMac
AppleScript: 2.4.3
Browser: Safari 537.31
Operating System: Mac OS X (10.7)

My guess is that a space is missing in your command.

Maybe better with :

  do shell script "cp " & FileSource & space & desktopPath

Yvan KOENIG (VALLAURIS, France) mercredi 27 mars 2013 15:10:13


to copy a directory (and its entire subfolders) you have to add the -R switch
and between source and destination path there must be a space character.
Furthermore the line will fail if any of the paths contains a space character
so each path should be quoted

 do shell script "cp -R " & quoted form of FileSource & space & quoted form of desktopPath