14 Replies Latest reply: Apr 23, 2013 2:08 AM by AliHuck RSS

    Applescript, XMP, and custom namespaces

    aklyman

      Having had to switch gears from JS to AS to solve a database integration problem, I could use some help getting specific XMP out of my AI files via AppleScript. Extracted this from the InDesign forums... doesn't work for illustrator (gives error "expected expression but found property")

       

      tell links

                  set InhouseClient to get property link xmp namespace "http://ns.Inhouse.com/Inhouse" path "Client"

      end tell

       

      I know I can dump the whole XMP string with:

       

      set XMPStringData to (get XMP string of current document)

       

      but I'd rather do something like the first example. If I were in JS, I'd use

      var property = myXmp.getProperty(propertyuri, propertyname, XMPConst.STRING);

      The syntax looks pretty close to the first AppleScript, but why is it choking on the "property" when inside a "tell Illustrator" when is works inside a "tell InDesign"?

        • 1. Re: Applescript, XMP, and custom namespaces
          Larry G. Schneider MVP

          Have you looked at the possibility of using the AS "do javascript" command?  From the manual

           

          do javascript

          Executes a JavaScript script and returns the result of execution.

          • 2. Re: Applescript, XMP, and custom namespaces
            aklyman Community Member

            I am considering this, but want to avoid as many moving peices as possible. I'm using FileMakerPro to create a calculation-defined AppleScript to extract XMP from Adobe CS files. I could pass parameters from the AS to the JS and back, but doing it all in AS would streamline both the development and (possibly/hopefully) shorten the run time. Preliminary tests using AS just to get the filepaths of the files I want from an irregular filesystem is already taking 10+ hours. I can call the XMP extract as a separate process, but expect similar time to run. Fewer moving parts = less time and more reliability.

             

            Might have to do it this way though. In fact, may want to. I suspect (probably erroneously) that JS will execute faster than AS, so if I have JS do the hard work of the lookup... hmmm, don't know how to test that to get real metrics.

             

            Anyone know if Finder (via AS) can extract XMP from AI files without telling illustrator to open the file first? FMP needs an add-on to do it (I think).

             

            Thanks,

            Alex

            • 3. Re: Applescript, XMP, and custom namespaces
              Muppet Mark Community Member

              I think you are in the wrong forum for this kind of scripting… I would NOT want to be opening AI files to extract XMP metadata. Using Adobe's ExtendScript I would either script Bridge or load the ESTK's external XMP library… This would be much much faster. That said FMP is AppleScript friendly ( wish I had it ). IMO you want to be looking at AppleScript's do shell script command this will blow Finder's little cotton socks off… You should take a look at ExifTool ( a great utility )…

               

              http://www.sno.phy.queensu.ca/~phil/exiftool/

               

              and ask your question either here:

               

              http://www.macscripter.net/viewforum.php?id=2

               

              or

               

              https://discussions.apple.com/community/mac_os/mac_os_x_technologies?view=discussions&tagS et=1044#/

               

              I would want finding files done in seconds/minutes NOT in hours? Do tell us more…?

              • 4. Re: Applescript, XMP, and custom namespaces
                aklyman Community Member

                Thanks for the suggestions Mark.

                 

                Here's the situation. We have approx 1TB of various files on multiple partitions of a server. I'm creating a library (FileMakerPro) to use as a search engine for specific AI files and associated metadata scattered throughout the server. We have a pattern of folders where the AI files I need live (jobFolder/Graphics/filename.AI), but these are nested in a variety of places.

                 

                I'm using set folderList to (folders of entire contents of (startFolder) whose name is "Graphics") as alias list to get a list of eligible folders to search, then checking to see if AI files are present, then adding the AI files to a list of file paths. This list is the source for other scripts to be called by Filemaker to extract the custom XMP, find and link to the preview (already generated in a separate folder).

                 

                Current times to ingest small sets of graphic paths using this method:

                Set 1, found 160 eligible folders with 1600 files in 44 minutes, or 17 seconds per folder/1.6 seconds per graphic.

                Set 2, found 310 eligible folders with 3800 files in 82 minutes, or 16 seconds per folder/1.3 seconds per graphic.

                Set 3, needs to crawl through about 8 times the number of folders, and can't finish before the server times me out (I pushed the AppleScript timeout to 20 hours, so that's not the problem).

                 

                In additon to metadata that has already been defined, I want to capture the full-text of the graphics in the DB for search purposes... so will have to open each file anyway to do that (unless there's another way).

                 

                Thanks,
                Alex

                • 5. Re: Applescript, XMP, and custom namespaces
                  Muppet Mark Community Member

                  Alex, you are using a combo of 2 AppleScript commands that are easy to write but the trade off is they are notoriously slow to execute… entire contents in finder takes an age plus the whose filtering you rearly need to swap this out for a little shell… do shell script has a memory overhead so call it as few times as possible but once called its fast… Do you need to locate just *.ai files in grahics folders or could you generic search *.ai?

                  • 6. Re: Applescript, XMP, and custom namespaces
                    aklyman Community Member

                    our folder heirarcy  Jobfolder/Graphics includes subfolders /Archive and /JPEGS (among others).

                     

                    /Graphics  contains a list of AI files sequentially numbered with a file iteration identifier letter, (e.g., graphic001a.ai, graphic002f.ai, graphic003b.ai), representing the most current iteration of every graphic.

                    /Graphics/Archive contains all prior versions(e.g., graphic001.ai, graphic002.ai, graphic002a.ai, graphic002b.ai, etc.).

                     

                    Finding *.ai would bring in many undesireable filenames.

                    /Graphics/*.ai is what I need.

                    • 7. Re: Applescript, XMP, and custom namespaces
                      Muppet Mark Community Member

                      It's been some time since I last used AppleScript & Shell but does this work to find your folders?

                       

                      set This_Folder to (choose folder with prompt "Select your top level folder…" without invisibles)

                       

                      set Folder_List to paragraphs of (do shell script "mdfind -onlyin " & quoted form of POSIX path of This_Folder & " 'kMDItemKind == \"Folder\" && kMDItemDisplayName == \"Graphics'")

                      • 8. Re: Applescript, XMP, and custom namespaces
                        aklyman Community Member

                        Runs, but returns {} on my test folder that contains several "Graphics" folders in different levels of directories.

                        Having done NO reading on shell yet....

                        • 9. Re: Applescript, XMP, and custom namespaces
                          Muppet Mark Community Member

                          What version of the OS are you running…? My AppleScript has become a little rusty… There are numberous ways to do what you want but you would be better served asking where I showed you… Basically you just need pipe two commands find | filter…

                          • 10. Re: Applescript, XMP, and custom namespaces
                            aklyman Community Member

                            Thanks Mark, I'll go looking there later today for a primer on shell.

                            I'm on 10.7.3

                            • 11. Re: Applescript, XMP, and custom namespaces
                              Muppet Mark Community Member

                              The above worked fine here listing all folders on my startup drive… Im at home so I can't check with mounted share… Some OS versions don't like the escaped quoting ie the \" but its best to get served by those who are up to date on AppleScript… If ExifTool works for you then you would find | filter | exiftool. Anyhows Im sure you will find a much faster solution than what you currently have…

                              • 12. Re: Applescript, XMP, and custom namespaces
                                aklyman Community Member

                                Oh my lord working with shell is FAST!!!

                                 

                                Working on a remote server, a little applescript calling a shell script is capturing the path for 20,000+ files in 2000+ jobs in a little over 5 minutes to ingest into my FMPro database. The applescript alone would have taken 30+ hours, and was getting interrupted by server time-outs.

                                 

                                Mark's "mdfind" wasn't working for me, probably because I was defaulting to a different shell script language.  What is working for me:

                                 

                                set fileString to (do shell script "find " & quoted form of searchPath & " -maxdepth 1 -iname *.ai")

                                 

                                which writes a list of off the paths to AI files found within the searchPath passed to the shell script.

                                 

                                Next step is to add a xmp lookup subroutine using EXIFTool... initial tests tell me this is the easy part.

                                 

                                Signed,

                                Recovering GUI Addict.

                                • 13. Re: Applescript, XMP, and custom namespaces
                                  Muppet Mark Community Member

                                  I did say it would blow finder's little cotton socks off… Glad you got it working…

                                  • 14. Re: Applescript, XMP, and custom namespaces
                                    AliHuck

                                    Hi

                                     

                                    I just saved each layer of text to pdf and then saved each pdf to xml, no scripting involved.

                                     

                                    Ali