Folder selector

Hi there.

I am completely new here. I got a little knowledge of apple scripting manly just putting terminal commands into a script. I want to run a terminal command.

cp -Rn /source/* /destination/

I can do that easily

do shell script “cp -Rn /source/* /destination/”

but what I want to be able to do is have a gui pop up and let me select the source folder and select the destination folder.

Possibaly would also like a box to show me what is happening if I used the v command to give an out put.

cp -Rnv /source/* /destination/

Can any one help me with this or tell me what I should search for relating to the folder selector part?

Thanks

Hi skeates,

Maybe code like follows will already give you some idea about the process:


property verbose : true

set sourcefolder to (choose folder with prompt "Please choose a source folder" without multiple selections allowed and invisibles)
set destfolder to (choose folder with prompt "Please choose a destination folder" without multiple selections allowed and invisibles)
set sourcefolder to quoted form of (POSIX path of (sourcefolder as Unicode text) & "*")
set destfolder to quoted form of POSIX path of (destfolder as Unicode text)
set command to "cp -Rn " & sourcefolder & space & destfolder
set output to do shell script command
if verbose is true then
	tell me
		activate
		display dialog output
	end tell
end if

Thanks that helps a lot.

I do how ever keep getting an error

cp: /Users/alexisskeates/Documents/test/01/*: No such file or directory

So not sure if the command part needs to be formatted differently?

This error is caused by this line:


set sourcefolder to quoted form of (POSIX path of (sourcefolder as Unicode text) & "*")

I added the asterisk, as you included it in your code example :smiley: Just remove it:


set sourcefolder to quoted form of POSIX path of (sourcefolder as Unicode text)

quoted form doesn’t work with asterisk wildcards included,
although the asterisk is outside the quotation, this works


set sourcefolder to quoted form of POSIX path of (sourcefolder as Unicode text) & "*"

Thanks.

That works, but the verbose not so well although it is not such a problem as I know it does the job.

Do you know if there is a way to run this as root (get it to prompt you for a password prior to doing the copy)?

Would this do it?

set command to "sudo cp -Rn " & sourcefolder & space & destfolder

The «do shell script» command offers some interesting properties:


set output to (do shell script command with administrator privileges)
-- This will automatically prompt you for the user name and password

Of course you can also add the user name and password directly:


set output to (do shell script command user name "Steve" password "Rocky Racoon" with administrator privileges)