Tuesday, January 16, 2018

#1 2013-06-04 09:35:07 am

mcquiff
Member
Registered: 2011-02-24
Posts: 185

Repeat from selection

I have this working from 1 file selected in finder, but how can I get it to repeat though a multiple selection?

Applescript:

set sel to the selection as text
       set thePath to POSIX path of sel
       do shell script "rm -rf " & thePath

Offline

 

#2 2013-06-04 09:47:43 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Repeat from selection

Hi,

for example

Applescript:


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


regards

Stefan

Offline

 

#3 2013-06-04 11:20:15 pm

ccstone
Member
Registered: 2009-02-07
Posts: 409

Re: Repeat from selection

mcquiff wrote:

I have this working from 1 file selected in finder, but how can I get it to repeat though a multiple selection?


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.

Applescript:

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:

Applescript:

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

Last edited by ccstone (2013-06-11 06:40:55 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)