• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script that "Tells" Finder just Focuses on Finder instead of running
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script that "Tells" Finder just Focuses on Finder instead of running


  • Subject: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 06 Jan 2015 12:44:10 +1100

On 6 Jan 2015, at 12:05 pm, Deivy Petrescu <email@hidden> wrote:

There's no real way of knowing that, as I see it. This is for a third party who is vision impaired, which presumably means he's likely to use it on *any* folder, and therefore it should try to cope with all possibilities.

Actually this makes the problem easier.
There should be a condition to stop the script from running (amok) on large folders.

OK. But you still have to make the call (ls or entire contents) to find out how many there are in the first place -- at which point you could be waiting ages for a result. This is another reason to consider doing the recursion yourself: you can pull the pin at an arbitrary number.

No question. But imagine the end user has his Applications folder open. He's going to be overwhelmed with information from a shell script. Or he has his home folder open -- entire contents is likely to time out.

Actually, as I said above, the script should not run if the folder in question has more than an acceptable but low number of files and folders.

But it has to run to find out how many files or folders there are.

But maybe I'm missing something. So let's say you're using entire contents -- can you show some code for how you intend to take that list of aliases or paths and format it something like Alex suggested?

Actually looking at the output of  theNSFileManager's subpathsAtPath:"/Users/shane" not just it was significantly faster than entire contents but the output is better to work with.
In any case, when I tried to run theNSFileManager's subpathsAtPath: “/Applications” it stalled ASE.

subpathsAtPath: is not a good choice because it's going to list everything inside every app bundle, and there are going to be zillions in /Applications. A better way is to use enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:. It's a bit more complex to use, but it lets you specify two important options: to skip invisible files, and to skip recursing into packages. The latter not only eliminates stuff you don't want, but it also speeds it up in this case massively. This takes about a second on my Mac for 57153 items:

use scripting additions
use framework "Foundation"

set thePath to POSIX path of (path to applications folder)
-- make NSURL
set anNSURL to current application's |NSURL|'s fileURLWithPath:thePath
-- get file manager
set theNSFileManager to current application's NSFileManager's defaultManager()
-- define options to use
set enumerationOptions to ((current application's NSDirectoryEnumerationSkipsPackageDescendants) + (current application's NSDirectoryEnumerationSkipsHiddenFiles as integer))
-- get enumerator
set theEnumerator to theNSFileManager's enumeratorAtURL:anNSURL includingPropertiesForKeys:{} options:enumerationOptions errorHandler:(missing value)
-- ask enumerator for all its files, and use valueForKey: to turn NSURLs into paths
set thePaths to (theEnumerator's allObjects()'s valueForKey:"path") as list

But again, formatting the results as Alex wanted still seems a fair bit of work. (And in passing he mentioned OS X 10.8.)

Now for what I believe it is a bug
The original script posted 

<script>
tell application "Finder"
set currentDir to (target of front window)
set CDir to currentDir as alias
set allFiles to (entire contents of CDir) as alias list
return (allFiles)
end tell
</script>

works fine. Now lets say that the target of the front window is my documents folder, this times out

<script>
tell application “Finder"
set allFiles to (entire contents of folder “HD:Users:deivy:Documents:”
end tell
</script>

Both pointing to the same folder.

It's not a bug so much as that getting Finder references takes a lot longer than getting a list of aliases. Actually, *getting* the information is not the problem -- it's building those Finder references to return that takes the time. Each of those "... of folder ..." bits has to be built separately, and that all adds up.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Script that "Tells" Finder just Focuses on Finder instead of running
      • From: Emmanuel LEVY <email@hidden>
    • Re: Script that "Tells" Finder just Focuses on Finder instead of running
      • From: Shane Stanley <email@hidden>
References: 
 >Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: 2551 <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)

  • Prev by Date: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Next by Date: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Previous by thread: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Next by thread: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Index(es):
    • Date
    • Thread