I have this working from 1 file selected in finder, but how can I get it to repeat though a multiple selection?
set sel to the selection as text
set thePath to POSIX path of sel
do shell script "rm -rf " & thePath
I have this working from 1 file selected in finder, but how can I get it to repeat though a multiple selection?
set sel to the selection as text
set thePath to POSIX path of sel
do shell script "rm -rf " & thePath
Hi,
for example
tell application "Finder" to set theSelection to selection
repeat with anItem in theSelection
set thePath to quoted form of POSIX path of (anItem as text)
do shell script "rm -rf " & thePath
end repeat
Stephan is on the money, except that getting the selection in the Finder produces Finder-references. That is very slow if there are many items selected.
Getting the selection as text or as alias list is much faster.
tell application "Finder" to set _sel to selection as alias list
if _sel ≠{} then
repeat with i in _sel
do shell script "file " & quoted form of POSIX path of i
end repeat
end if
The reason your script was working alright with one item is that the coercion to text produces a single text item. For a single Finder item that works fine, but it doesn’t work for multiple items.
To use the text method for multiple items you’d need to do something like:
set AppleScript's text item delimiters to return
# Produce a list of items to iterate through:
tell application "Finder" to set _sel to paragraphs of (selection as text)
if _sel ≠{} then
repeat with i in _sel
do shell script "file " & quoted form of POSIX path of i
end repeat
end if