• 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: How can I speed up execution time of this script in case of many files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I speed up execution time of this script in case of many files


  • Subject: Re: How can I speed up execution time of this script in case of many files
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 01 Aug 2013 22:52:27 -0500

On Aug 01, 2013, at 16:19, Bert Groeneveld <email@hidden> wrote:
Hi, I wrote a script to check if files in an incoming folder are stabilized for further processing. It works fine, but unfortunately very very slow with large amount of files (let's say more then 500 files). How can I speed up execution time with many files?
______________________________________________________________________

Hey Bert,

First and foremost never use Finder references unless you have a good reason to do so; they are painfully slow.

With a test sample of 500 files in Script Debugger with debugging [off]:

tell application "Finder"
set fl to target of front window as alias # Even this is faster when you coerce to alias.
set aliasList to files of fl as alias list     # This is much faster than Finder References.
end tell

# ~ 0.75 seconds (as alias list)
# ~ 12 seconds (Finder References)

Peter is right too.  Don't split up your operations unless you need to.

tell application "Finder"
set fl to target of front window as alias
set aliasList to files of fl as alias list
repeat with i in aliasList
set n to name of i
end repeat
end tell

# ~ 1.35 seconds (Repeat inside Finder-Tell)

tell application "Finder"
set fl to target of front window as alias
set aliasList to files of fl as alias list
end tell
repeat with i in aliasList
tell application "Finder"
set n to name of i
end tell
end repeat

# ~ 3.02 seconds (Repeat outside Finder-Tell)

-------------------------------------------------------------------------------------------
A fast non-Finder alternative:
-------------------------------------------------------------------------------------------

set fl to (path to home folder as text) & "test_directory:Many_Files:"
set fileList to do shell script "ls -1 " & quoted form of POSIX path of fl & " | sed -E 's/^/" & fl & "/'"
set fileList to paragraphs of fileList
repeat with i in fileList
set contents of i to (contents of i) as alias
end repeat
fileList

# ~ 0.15 seconds (for the same 500 files)

-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
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: How can I speed up execution time of this script in case of many files
      • From: Bert Groeneveld <email@hidden>
References: 
 >How can I speed up execution time of this script in case of many files (From: Bert Groeneveld <email@hidden>)

  • Prev by Date: Re: How can I speed up execution time of this script in case of many files
  • Next by Date: Re: How can I speed up execution time of this script in case of many files
  • Previous by thread: Re: How can I speed up execution time of this script in case of many files
  • Next by thread: Re: How can I speed up execution time of this script in case of many files
  • Index(es):
    • Date
    • Thread