Since you are doing this in Automator, with a Run AppleScript acton, this will do what you need:
on run {input, parameters}
set theItemsToScanList to {}
repeat with i from 1 to count input
set end of theItemsToScanList to quoted form of (POSIX path of (item i of input as string)) & space
end repeat
tell application "Terminal"
activate
do script with command "clamscan --bell -i " & theItemsToScanList
end tell
end run
There is no need to complicate things and go through the rigmarole shown in the other answer!
Or if you choose to do it in a plain AppleScript script/application, then this will do what you need:
set theseItems to application "Finder"'s selection
set theItemsToScanList to {}
repeat with i from 1 to count theseItems
set end of theItemsToScanList to quoted form of (POSIX path of (item i of theseItems as string)) & space
end repeat
tell application "Terminal"
activate
do script with command "clamscan --bell -i " & theItemsToScanList
end tell
Note: The example AppleScript code above is just that, and does not include any error handling as may be appropriate/needed/wanted, the onus is upon the user to add any error handling for any example code presented and or code written by the oneself.
1The OP is using Terminal's
do script
command not AppleScript'sdo shell script
command. The immediate issue I see you your answer is if more then one file and say lots of files are selected, while the--bell
option of theclamscan
command may ring, so to speak, how is one going to know which of the lots of files selected is the infected one?-i
, which would print infected files, is useless in ado shell script
command unless you're going to set its output to a variable and then parse it some how, but not in Terminal'sdo script
command. Something to think about! – user3439894 – 2018-01-14T22:54:37.540Thanks for the heads-up.. Working on another post at the moment but I will come back to this one shortlyAnd make the necessary changes – wch1zpink – 2018-01-14T22:57:23.457
The final output to shell command must be this: clamscan -I —bell ‘/path/file1’ ‘/path/file 2’ e.t.c. – COOL_IRON – 2018-01-15T04:28:16.687
Addressed the issue.. Updated the code – wch1zpink – 2018-01-15T05:40:53.910
Your answer has unneeded properties, which you are setting and unsetting, unneeded multiple
repeat
loops. The OP is using Automator and a Run AppleScript action, so the only variable, and it doesn't need to be aproperty
, istheItemsToScanList
as alist
, and only onerepeat
loop to process theitems of input
into it, with a single command line within therepeat
loop. You're using 21 lines of code where it can be done with 8 lines of code added to the Run AppleScript acton in order to achieve the goal of the OP. – user3439894 – 2018-01-15T10:22:42.327