Tuesday, June 27, 2017

#26 2012-10-25 01:37:45 pm

McUsr
Member
From: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Return a list of Folders and Subfolders

Hello.

When the handler are fed the "all" or "every" result type, then it returns a list.

You'd have to iterate over that list with something like this:

Applescript:


repeat with anObj in theResultList
   tell application "System Events" to tell disk item (contents of anObj) to set {ParentFolder, Foldername} to {POSIX path of container of it, name of it}
   display dialog "Path to Folder:" & objItem & return & "Parent Folder of Folder " & ParentFolder & return & "Name of Folder: " & Foldername
end repeat

# the contents of is included, as it doesn't harm, though I am not sure if it is totally needed either.

# as the "iterator-variable" just contains a reference into the list, and I am not sure how far
# Applescript will go into coercing this.

There are much faster approaches to this, than using this kind of construct, you could for instance use a handler like this to extract the information with.

Applescript:



set pxPath to POSIX path of (path to temporary items from user domain as text)
—> "/Users/mcusr/Library/Caches/TemporaryItems/"
set thPath to parentFol for pxPath
— > /Users/mcusr/Library/Caches/"

set folname to pxBasename for pxPath
—> "
TemporaryItems"

to parentFol for aPxPath
       local tids, parFol
       set {tids, my text item delimiters} to {my text item delimiters, "
/"}
       
       if (character (length of aPxPath) of aPxPath) = "
/" then
           set parFol to text items 1 thru -3 of aPxPath as text
       else
           set parFol to text items 1 thru -2 of aPxPath as text
       end if
       set my text item delimiters to tids
       if parFol = "
" then set parFol to "/"
       return parFol
   end parentFol

to pxBaseName for aPxPath
   local itm,tids
   if (text -1 of aPxPath = "
/") then
       set itm to -2
   else
       set itm to -1
   end if
   set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "
/"}
   set aPxPath to text item itm of aPxPath
   set AppleScript's text item delimiters to tids
   return aPxPath
end pxBaseName

Now, you could extract this info into a list, like I did with System Events, but it is no purpose of that now. (I did it with System Events to not generate to many Apple Events, as those are expensive, and choose to target the disk item, to give its properties in one go. smile


Mercurial vcs is a joy to use for scripting.

Filed under: mdfind

Offline

 

#27 2012-10-26 04:26:14 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 113

Re: Return a list of Folders and Subfolders

Hi McUsr

I have tried the first suggestion and the problem is that the "repeat with  anOBJ in MyFolderList" returns the entire list on the first iteration and then fails on (I assume the second) because it cannot get the disk item U/ and the list starts /Users/----. I need to break the list down to each entry which is why I asked about delimiters before. As each folderpath starts with/Users I was hoping to use that as a delimiter, but as I said have not figured how.

Thanks

Peter

Offline

 

#28 2012-10-27 03:01:20 am

McUsr
Member
From: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Return a list of Folders and Subfolders

Can you please just show an excerpt of the code.

I'd rally like to see your loop, and how you do it, before I can make an educated guess as to why your code fails.

On a general basis, please consult the AppleScript Language guide, that is either on the net at developer.apple.com, or as a part of the Developer installation from your CD, if you got them there, I also think you can get it all for free from the Appstore, Xcode, the documentation and everything.

The easiest is of course to just download it. big_smile

I

Last edited by McUsr (2012-10-27 03:45:53 am)


Mercurial vcs is a joy to use for scripting.

Filed under: mdfind

Offline

 

#29 2017-06-04 08:24:42 pm

JMichaelTX
Member
From: Houston, TX (The Woodlands)
Registered: 2014-07-12
Posts: 133

Re: Return a list of Folders and Subfolders

Marc Anthony wrote:

Applescript:

tell application "Finder" to ((path to documents folder)'s entire contents's folders whose name is in my getList())

on getList()
   tell application "Mail" to inbox's message's subject
end getList

Marc et al:  I've very impressed with this whose clause.  I've never seen anything like it, but would like to make use of this pattern.

However, it gets an error when I try this:

Applescript:


tell application "System Events"    
   set appNameList to every application process whose name is in my getList()
end tell

on getList()
   return {"Keyboard Maestro", "Finder", "Script Debugger"}
end getList

(*
=== ERROR ===
System Events got an error: Can’t make {"Keyboard Maestro", "Finder", "Script Debugger"} into type specifier.
*)

Any ideas/suggestions?

TIA.


iMac-27 Late 2015 Retina 5K Screen (& others)
macOS 10.11.6 (El Capitan)

Filed under: handler, whose

Offline

 

#30 2017-06-05 03:36:19 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3059

Re: Return a list of Folders and Subfolders

Hello

My understanding is that you just need to insert a timeout.

This script behaved flawlessly :

Applescript:

with timeout of 36000 seconds
   tell application "Finder" to ((((path to desktop as text) & "pour ebay:") as alias)'s entire contents)'s folders whose name is in my getlist()
end timeout
on getlist()
   return {"_X28706ƒYK", "_X28737ƒYK", "_X28782ƒYK", "_X28990ƒYK", "_X29050ƒYK", "_X29066ƒYK", "_X29075ƒYK", "_X29101ƒYK", "_X29109ƒ"}
end getlist

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 5 juin 2017 10:32:25

Offline

 

#31 2017-06-06 06:49:54 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2654

Re: Return a list of Folders and Subfolders

JMichaelTX wrote:

Marc et al:  I've very impressed with this whose clause.  I've never seen anything like it, but would like to make use of this pattern.

Those are called filters and they are object specifiers. However, due to poor implementation they're hard to manage and a lot of applications don't support them. There is an KVC compatible way of coding to save yourself from writing many object accessor methods, but again there is no guarantee that the application supports it.

From what I can see is that the accessor method doesn't support the is in operator but it does supports other operators like is. That means that when you use the is in operator the object cannot be resolved and therefore you get the type specifier error.

Last edited by DJ Bazzie Wazzie (2017-06-06 06:50:43 am)

Offline

 

#32 2017-06-06 01:45:05 pm

t.spoon
Member
From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 185

Re: Return a list of Folders and Subfolders

mdfind can do case-insensitive search.

https://hacksformacs.wordpress.com/2015 … and-xargs/

Syntax is:

mdfind '"searchstring"c'


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.043 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)