"do shell script" question

Hi -

I would like to use the command “do shell script” and tell my script to retrieve a group of files from a mounted volume. I’ve got the basic structure for that, as seen below:

do shell script "cd ~/Desktop/batch; cp /Volumes/MyDisk/Files/*.jpg ."

What I would like to do is use this same script repeatedly, but retrieve my files from different folders on the mounted volume without having to open the script each time and manually type the new path.

I thought that maybe a prompt would work, like:

tell application "Finder"
set batchDir to choose folder with prompt "Where are the files you want to copy?"
end tell
do shell script "cd ~/Desktop/batch; cp batchDir ."

but, I don’t think I can use a variable like batchDir inside quotes for my shell script command. Any suggestions for how to do this elegantly?

Much appreciated,


erm are the foldes fixed???

if so then i suggest putting them in a list and then doing a repeat loop.


set theFolderList to {"path:to:folder1:","path:to:folder2"}
set foldCount to (count theFolderList)

repeat with i from 1 to foldCount
set theFolder to item i of theFolderList
--now do the shell thingy, that bit i dont know sorry
end repeat 

That should get you started, if the folders are different then i suggest putting the paths into a file (this is how i would do it, not very good i suppose but works) seperate each with return and then call the file through as text.

That might be the easiest way to program it, with my kowledge it is anyway.

property thePathFile: path to file as alias

set theList to read thePathFile as list using delimiter return
repeat with i from 1 to x 

set theFolder as item i of thePathFile as alias


I reckon that might work. They others will let us knowm, hopefully

Hi Daveyand -

The folders are not fixed, unfortunately. This is a script that will run once each week, so its going to look for a different folder on the mounted volume each time. That’s why I don’t want to have to open the script each time to change the path. I was kind of hoping to eventually (after its written) to make it activated by a cron job, thus making everything very automated.

Hope that helps - please keep sending me help!



The above code won’t work as expected since you’re passing the literal text ‘batchDir’ to the shell script, not the contents of the variable.

Fortunately, the solution to incorporating variables in shell scripts is simple:

ell application "Finder"
set batchDir to choose folder with prompt "Where are the files you want to copy?"
end tell
do shell script "cd ~/Desktop/batch; cp " & POSIX PATH of batchDir & " ."

In other words, use & to concatenate the parts of the string and variables.

In this case you need to use ‘POSIX path of’ since batchDir is a folder, not a string, and POSIX path coerces a folder to a unix-style pathname.

However, you can actually do all this in the Finder rather than in a shell script using the Finder’s ‘duplicate’ command, but either way is fine.

Thanks! Sorry for the late reply - just finally had a chance to check back on this. I’ll definitely try that.