4 Replies Latest reply: Jan 5, 2012 3:12 AM by Bernard Harte
Bernard Harte Level 4 Level 4 (3,165 points)

I have a folder that contains a mix of folders and files.  (About 80:20.)

 

I want to get a list of the files, and this works fine:

 

     tell application "Finder"

 

               files of (selection as alias)

 

     end tell

 

 

However, if I try this:

 

     property fileList : {}

 

     tell application "Finder"

 

        set my fileList to (files of (selection as alias))

 

     end tell

 

It will consistently crash the AppleScript Editor app when I run.

 

Saving this script as an app and running that (with an appropriate display dialog to show the first item of the list) works fine first time, but second time around will give a -2707 Internal Table Overflow error.

 

There's obviously some corruption somewhere, but I have had a go at deleting prefs files, restarting etc and can't find a resolution.  (Incidentally, this was all working fine until a couple of days ago, but nothing has changed on the system in the meantime.)

 

Does anyone know how to fix please?

 

 

 

 



MacBook Pro, Mac OS X (10.7.2), 13" Late 2011 8GB RAM
  • twtwtw Level 5 Level 5 (4,900 points)

    selection in the Finder is a reference to a list of Finder items; the my keyword creates a reference to the fileList property you've declared.  I suspect there are just too many coersions involved trying to convert selection directly to an alias, doing a filter on the alias, and then reconverting it to a new reference list.  does it clear things up if you do this?

     

    property fileList : {}

     

    tell application "Finder"

              set sel to get selection -- dereferences the selection

              set my fileList to (files of item 1 of sel)

    end tell

  • Bernard Harte Level 4 Level 4 (3,165 points)

    I am afraid it's not that - but thanks.

     

    On this occasion, I don't really need the list as a property but it's definitely the assignment to 'my' list that's causing the problem - leaving out the property declaration and simply setting a var to fileList seems to work fine.

     

    It's all strange since - as I said in my original post - the problem did not exist previously.

     

    I am still keen to find the answer as scripts that run faster with lists as properties will not work.

  • twtwtw Level 5 Level 5 (4,900 points)

    well, I can't replicate the problem you're finding with a simple test on my computer: how many items are in this folder you're working with?  Your two examples aren't exactly parallel (you're not setting a variable in the first one the way you are in the second), but assuming the 'my' keyword is the source of the problem then it's almost certainly a question of trying to set a reference from a different reference.

     

    I'll add that (depending on what you're trying to do) you might not even get a speed boost by using properties inside a Finder tell.  the choke-point is likely to be the Finder itself (the Finder was not designed for scriptability - that was added after the fact, so you get mixed results scripting the Finder).  what is the greater goal here?  You might find better results scripting System Events and leaving the Finder out of it.

  • Bernard Harte Level 4 Level 4 (3,165 points)

    It's OK, thanks.

     

    I was using a list as property to do a lookup on a list of lists.

     

    However, the problem only seems to be when populating the list from the Finder (which - as I said - was working a few days ago).

     

    Anyway, I have found that I can get what I want working again simply by making an interim list from the finder and iterating through this (adding other data) to build my list of lists which is set as a property.

     

    To answer your question, the number of files/folders involved is not huge (around 1500 total) but I take your point that AS is retrofitted onto the Finder.  For that reason I often use a shell script to manipulate files.  On this occasion I didn't and that confounded me!