Hi There
I am working on a script for copying flies to a remote server using ssh.
Everything is working but for the multiple selection part - only one file gets copied.
I know I am overlooking somethin but what?
set theUser to " me"
set theAdress to "192.168.1.1"
set theCommand to ("scp -B -r -p " as Unicode text)
set the_files to choose file with prompt "What to Copy?" with multiple selections allowed without invisibles
repeat with the_file in the_files
set the_unix_file_path to the quoted form of POSIX path of the_file
end repeat
display dialog "Copy to Where?" buttons {"me", "TS-Leenbakker", "User Defined"} default button 1 with title "Copy Files"
copy the result as list to {ChoosenFolder}
if ChoosenFolder is "me" then
set Destination to ":~/"
with timeout of 864000 seconds
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & Destination & "\"\""
end timeout
else
if ChoosenFolder is "TS-Leenbakker" then
set TopDestination to ":/TS-Leenbakker"
repeat
set Destination to "Destination? (ex: /10/101/)"
set tempDest to display dialog Destination default answer ""
set DestinationEntered to text returned of tempDest
display dialog "Is " & DestinationEntered & " OK?" buttons {"Back", "Continue"} default button 2
if the button returned of the result is "Continue" then exit repeat
end repeat
with timeout of 864000 seconds
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & TopDestination & DestinationEntered & "\"\""
end timeout
else
if ChoosenFolder is "User Defined" then
set TopDestination to ":"
repeat
set Destination to "Destination? (ex: /path/to/folder/)"
set tempDest to display dialog Destination default answer ""
set DestinationEntered to text returned of tempDest
display dialog "Is " & DestinationEntered & " OK?" buttons {"Back", "Continue"} default button 2
if the button returned of the result is "Continue" then exit repeat
end repeat
with timeout of 864000 seconds
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & TopDestination & DestinationEntered & "\"\""
end timeout
end if
end if
end if
tell application "Finder"
activate
display dialog "Files Copied" buttons {"OK"} default button 1
end tell
first of all: the timeout blocks are completely useless. You can omit all of them.
Timeout blocks affect only Apple Events (sent to applications).
Also the Unicode coercion in the third line is useless. A shell script call coerces the argument silently to UTF if needed
To process all files actually move the first end repeat line after the last end if
Edit I don’t understand the double quotes at the end of the shell script lines
You are right , no need for this.
One more thing:
I have to specify a destination for each file when selecting multiple items.
What I want is to specify it just one time for all the selected files ( the TS-Leeenbakker and User Defind options)
set theUser to " me"
set theAdress to "192.168.1.1"
set theCommand to "scp -B -r -p "
set the_files to choose file with prompt "What to Copy?" with multiple selections allowed without invisibles
repeat with the_file in the_files
set the_unix_file_path to the quoted form of POSIX path of the_file
display dialog "Copy to Where?" buttons {"me", "TS-Leenbakker", "User Defined"} default button 1 with title "Copy Files"
copy the result as list to {ChoosenFolder}
if ChoosenFolder is "me" then
set Destination to ":~/"
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & Destination
else
if ChoosenFolder is "TS-Leenbakker" then
set TopDestination to ":/TS-Leenbakker"
repeat
set Destination to "Destination? (ex: /10/101/)"
set tempDest to display dialog Destination default answer ""
set DestinationEntered to text returned of tempDest
display dialog "Is " & DestinationEntered & " OK?" buttons {"Back", "Continue"} default button 2
if the button returned of the result is "Continue" then exit repeat
end repeat
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & TopDestination & DestinationEntered
else
if ChoosenFolder is "User Defined" then
set TopDestination to ":"
repeat
set Destination to "Destination? (ex: /path/to/folder/)"
set tempDest to display dialog Destination default answer ""
set DestinationEntered to text returned of tempDest
display dialog "Is " & DestinationEntered & " OK?" buttons {"Back", "Continue"} default button 2
if the button returned of the result is "Continue" then exit repeat
end repeat
do shell script theCommand & the_unix_file_path & theUser & "@" & theAdress & TopDestination & DestinationEntered
end if
end if
end if
end repeat
tell application "Finder"
display dialog "Files Copied" buttons {"OK"} default button 1
end tell
set theUser to " me"
set theAdress to "192.168.1.1"
set theCommand to "scp -B -r -p "
set the_files to choose file with prompt "What to Copy?" with multiple selections allowed without invisibles
display dialog "Copy to Where?" buttons {"me", "TS-Leenbakker", "User Defined"} default button 1 with title "Copy Files"
copy the result as list to {ChoosenFolder}
if ChoosenFolder is "me" then
set Destination to ":~/"
set theParameter to theUser & "@" & theAdress & Destination
else
if ChoosenFolder is "TS-Leenbakker" then
set TopDestination to ":/TS-Leenbakker"
set Destination to "Destination? (ex: /10/101/)"
else
set TopDestination to ":"
set Destination to "Destination? (ex: /path/to/folder/)"
end if
repeat
set tempDest to display dialog Destination default answer ""
set DestinationEntered to text returned of tempDest
display dialog "Is " & DestinationEntered & " OK?" buttons {"Back", "Continue"} default button 2
if the button returned of the result is "Continue" then exit repeat
end repeat
set theParameter to theUser & "@" & theAdress & TopDestination & DestinationEntered
end if
repeat with the_file in the_files
set the_unix_file_path to the quoted form of POSIX path of the_file
do shell script theCommand & the_unix_file_path & theParameter
end repeat
tell application "Finder"
display dialog "Files Copied" buttons {"OK"} default button 1
end tell