• 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 to speed up execution time of this script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to speed up execution time of this script


  • Subject: Re: How to speed up execution time of this script
  • From: CYB <email@hidden>
  • Date: Mon, 09 Aug 2010 21:47:33 -0500
  • Thread-topic: How to speed up execution time of this script

Title: Re: How to speed up execution time of this script
Bert,
I know that you already have some solutions, but I think that could be interesting to see other approach
I have a very similar situation here, we have more that 15,000 photographic files of one client and we named all the files starting with it’s product code, 4 to 6 digits.
So it’s very useful to have this information in a database, because not just have the name , you can store a lot of info there and have access to it very fast.
So I send you a script based on Database Events free and already in your Mac.
The first part build the database, so you just need to run it the first time or every time the contents of your folder change
Here this first part took less than 10 seconds
the second part depend on how many files found, but it tool less that 2 seconds to found 156 files.
This sample database have 2 fields, but of course you can add as many as  you need

-->> SCRIPT ---Start copying here-----
property FolderDAM : alias "MacPro:Users:cysunza:Pictures:Originales:" -- actual path of your images folder
property NameOfDatabase : "ListaOriginales.dbev" -- the name that you want for your database

global PathToDatabase

set PathToDocs to path to documents folder
set PathToDatabase to (PathToDocs as text) & "Databases:" & NameOfDatabase --this is tha path where you will save you database

-->> Subroutine to build the database
Build_MyDataBase(PathToDatabase) --make a fresh database with  the name of every file in your folder and it's actual path
--you need to build it just every time the contents of your repository folder change, so after the first run maybe you want to commented out this line

-->> ask for your request
set MyRequest to text returned of (display dialog "Type your request" default answer "6615")
-->> Subroutine to make the query
Query_MyDataBase(MyRequest) -- it will look for your files

--- SUBROUTINES
to Query_MyDataBase(MyRequest)
    set MyDataBase to POSIX path of PathToDatabase
   tell application "Database Events"
       tell database MyDataBase
           set PathToFoto to get value of field "PathArchivo" of (every record whose value of field "NombreArchivo" starts with MyRequest)
            if PathToFoto = {} then tell me to display dialog "No file with this data"
       end tell
   end tell
   return PathToFoto
end Query_MyDataBase

to Build_MyDataBase(PathToDatabase)
    tell application "Finder"
       set ListaNombres to name of (document files of entire contents of FolderDAM) --as alias list
       set ListaPathToFotos to (document files of entire contents of FolderDAM) as alias list
   end tell
   set CuantosRegistros to count of ListaNombres -- count how many files
   set NombreCampos to {"NombreArchivo", "PathArchivo"} -- names of database fields
   tell application "Database Events"
       delete every database
       if (exists database PathToDatabase) then
           set BaseListaFotos to database PathToDataBase_ListaFotos
       else -- build the database
           set BaseListaFotos to make new database with properties {name:NameOfDatabase}
        end if
       tell BaseListaFotos
           repeat with i from 1 to CuantosRegistros
               set Registro to make new record with properties {name:"Foto_" & i as text}
                tell Registro -- populate the records with the actual data
                   set CampoNombre to item 1 of NombreCampos
                   set DatosNombre to item i of ListaNombres
                   make new field with properties {name:CampoNombre, value:DatosNombre}
                    set CampoPath to item 2 of NombreCampos
                   set DatosPath to item i of ListaPathToFotos
                   make new field with properties {name:CampoPath, value:DatosPath}
                end tell
           end repeat
       end tell
       --delete every database
   end tell
end
Build_MyDataBase
-->> END OF SCRIPT

I hope you found it useful.

Carlos Ysunza B.
Director
Ysunza/Santiago
Visual Communication • Automation
Tel. (52)55 5256-0336
email@hidden

http://www.ysunzasantiago.com
http://www.thesecretmexico.com
http://www.softrobot.com.mx

 _______________________________________________
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

References: 
 >How to speed up execution time of this script (From: Bert Groeneveld <email@hidden>)

  • Prev by Date: Filemaker Basics
  • Next by Date: Re: Libraries and effiency
  • Previous by thread: Re: How to speed up execution time of this script
  • Next by thread: Re: How to speed up execution time of this script
  • Index(es):
    • Date
    • Thread