Reputation: 1091
I have been working on this project for my job, which involves backing up selected information from a computer to one of our servers. So far I have posted a couple of questions and gotten a lot of valuable help, so thanks everyone for that! The current bug that I have hit is when attempting to duplicate a selection involving multiple errors. If I try and duplicate one folder it works just fine, but multiple just isn't quite working. The code is below
display dialog "Please enter your augnet username" default answer "username"
set username to (text returned of result)
set server to "smb://orgs.augsburg.edu"
try
mount volume server
on error
display dialog "Either you are already connected, or there was a problem reaching the server. Please disconnect and try again."
end try
delay 3
tell application "Finder"
set backup to make new folder at folder "ORGS:Information Technology:www:kb_images:Migration Testing:" with properties {name:username}
end tell
set theSelection to choose folder with prompt "Please select what you would like to transfer" with multiple selections allowed
tell application "Finder" to duplicate folder theSelection to backup
Any help any of you can give me involving a selection with multiple folders is very much appreciated!
Upvotes: 0
Views: 531
Reputation: 3413
The choose folder … with multiple selections allowed
command will return a list of alias objects pointing to folders (unless canceled, of course). Just iterate over that list with a repeat
loop:
set selectedFolders to choose folder with prompt "Yadda" with multiple selections allowed
repeat with selectedFolder in selectedFolders
-- do something with the folder
end repeat
Generally speaking, when in doubt what a command returns, just execute it and look at the output in the AppleScript Editor result window. In your case, it would look something like this:
– which tells you all you need to know: the returned data is a list (it’s enclosed in braces, {
and }
) and contains alias objects denoted by their HFS path. As to basics like looping, the Applescript Language Guide (reachable through AppleScript Editor’s help menu) has all the details you need.
Finally, I’d recommend using System Events instead of Finder for the copy operation, as it is faster and operates in the background.
Upvotes: 1