Need help optimizing an Applescript


i'm new scripting google , forums this, able come script need, problem is pretty slow , hoping me optimize it.

manage , organize thousands of files have multiple versions of same content. script looks through selected files, , moves them folder based on last 3 numbers of filename, way different versions of same content collected in single folder. again, script works great, wondering if there speed up. in advance!

code:
on run {input, parameters} -- create folders file names , move         set output {} -- list of moved files         repeat anitem in input -- step through each item in input         set {thecontainer, thename, theextension} (getthenames anitem)         try             set destination (makenewfolder thename @ thecontainer)             tell application "finder"                 move anitem destination                 set end of output result alias -- success             end tell         on error errormessage -- duplicate name, permissions, etc             log errormessage             # handle errors if desired - skip         end try     end repeat         return output -- pass on results following actions end run  getthenames someitem -- container, name, , extension file item     tell application "system events" tell disk item (someitem text)         set thecontainer path of container         set {thename, theextension} {name, name extension}     end tell     if theextension not ""         set thename text -7 thru -((count theextension) + 6) of thename -- name part         set theextension "." & theextension     end if     return {thecontainer, thename, theextension} end getthenames   makenewfolder thechild @ theparent -- make new child folder @ parent location if doesn't exist     set theparent theparent text     if theparent begins "/" set theparent theparent posix file text     try         return (theparent & thechild) alias     on error errormessage -- no folder         log errormessage         tell application "finder" make new folder @ theparent properties {name:thechild}         return result alias     end try end makenewfolder
 

i think having finder test thousands of times whether folders exist taking time. fast, @ least of mavericks. found script used work no longer worked because fast. needed add small delay @ 1 point let app , finder in sync.

more work, run through input list once , create list of versions need folders created them (probably short list). testing if short string "004" belongs list hugely faster having finder go out , check if folder "004" exists , trapping error if doesn't.

test if few folders described list exist or need created run loop move files.

2 cents.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

OS X El Capitan on Unsupported Macs

[SOLVED] SFOTT usb key not bootable Mavericks

Fernando Torres: One of the all-time greats?