Apple script is stuck working with Numbers

Hello, everyone
I need some help.
I wrote a script what was supposed to do perform following:
I receive a Numbers-format file imported to my Mac from iPad with iTunes
This file is a sort of daily journal. Every row includes info about one particular client. A name of the client is in column 2. The file name is always "Blank.numbers" and the table name is always "Blank". I need to copy this table in a new file and collect the data for each client in a different table . In other word i need to make new tables in a new file and copy client info in its own table.
The script is below. It seems to work right (it makes a new file, makes some tables, puts correct info into them) but one thing happens  - it's stuck in a little while after run. Sure, I reloaded my Mac and not ones but nothing at all - zero effect, the same thing happened over again, after the script successfully worked it  was stuck and i just could see "running". My test data file consists of just up to 40 rows, but I've never had this work completely done. 
Not much scriptwriter of myself - it's just my very first experience in the subject and I have no clue about why it could be, so I'll appreciate for any suggestion
on run
     set FileName to "Blank.numbers"
     set ClientColumn to 2
     set CashFlowSheetName to "Cash Flow"
     tell application "Numbers"
          activate
          set FileName to "Blank.numbers"
          set ClientColumn to 2
          set WorkDocument to my makeAnNumbersDoc("Blank.nmbtemplate")  -- creating a new file
          tell document WorkDocument to tell sheet 1
               set name to CashFlowSheetName
               delete table 1
          end tell
          set Clients to my GetListOfClients(FileName, ClientColumn) -- getting full list of the clients
          repeat with i from 1 to count of Clients
               set FullCopy to my GetTable("Blank.numbers", item i of Clients, ClientColumn)  -- choosing data
               my MakeTable(WorkDocument, CashFlowSheetName, FullCopy, item i of Clients) -- making table with name of  a client for every client
          end repeat
     end tell -- numbers
     return my GetListOfClients(FileName, ClientColumn) -- test line, del me!
end run
on MakeTable(WorkDocument, WorkSheet, DataList, Client)
     local i, j
     tell application "Numbers"
          tell document WorkDocument to tell sheet WorkSheet
               make new table with properties {row count:count of DataList, column count:count of item 1 of DataList, name:Client}
               tell table Client
                    repeat with i from 1 to row count
                         repeat with j from 1 to column count
                              set t to value of item j of item i of DataList
                              if class of t is date then set t to t - (time to GMT)
                              set value of cell j of row i to t as text
                              --say "column"
                         end repeat
                    end repeat
               end tell -- table
          end tell -- sheet
     end tell -- Numbers
end MakeTable
on GetListOfClients(FileName, TargetColumn)
     local i, FullListOfClient
     tell application "Numbers"
          open ":Users:Master:Documents:" & FileName
          set FullListOfClient to {}
          tell document 1 to tell sheet 1 to tell table 1
               repeat with i from 2 to count row
                    if value of cell TargetColumn of row i is not in FullListOfClient then copy value of cell TargetColumn of row i to the end of FullListOfClient
               end repeat
          end tell
     end tell
     return FullListOfClient
end GetListOfClients
on GetTable(DocName, TargetValue, TargetColumn)
     local RowCounter, CopyRow
     tell application "Numbers"
          tell document DocName
               tell table 1 of sheet 1
                    set RowCounter to 1
                    set CopyRow to {}
                    copy cells of row 1 to the end of CopyRow
                    repeat with RowCount from 1 to row count
                         if value of cell TargetColumn of row RowCounter is equal to TargetValue then
                              copy cells of row RowCounter to the end of CopyRow
                         end if
                         set RowCounter to RowCounter + 1
                    end repeat
                    return CopyRow
               end tell
          end tell
     end tell
end GetTable
--=====
Creates a new Numbers document from Blank.template
and returns its name.
on makeAnNumbersDoc(myTemplate)
     local t, n
     set theApp to "Numbers"
     set t to ((path to applications folder as text) & theApp & ".app:Contents:Resources:Templates:" & myTemplate & ":") as alias
     tell application "Numbers"
          set n to count of documents
          open t
          repeat
               if (count of documents) > n then
                    exit repeat
               else
                    delay 0.1
               end if
          end repeat
          set n to name of document 1
     end tell -- theApp
     return n
end makeAnNumbersDoc

Hello
Then I have no idea why the script hangs after it has done the job.
Some thoughts.
• Is it the same in different user account?
• If you force quit the script, is the resulting new document fine? In other words, is the problem limited to the termination of the script? You can quit a running script by means of i) pressing command + period, which will signal to cancel the execution of the script or ii) killing the process (editor or applet) by Activity Monitor.
Anyway, I have done some clean up and optimization of your script as listed below although I can see no reason for these changes to solve the current issue. It is just for my testing and liking for low energy consumption.
Script is revised so that -
a) it gets the template path indepent of the location of Numbers.app;
b) it reduces the number of AppleEvents to send for retrieving data from table by means of range reference form (e.g., rows i thru j) and whose filter reference (e.g., rows whose cell i's value = x);
c) its GetTable() handler now returns 2d arary of values instead of cell references so that it can reduce the number of AppleEvents for dereferencing the cell reference later;
d) it introduces _main() handler to localise the implicit global variables in run handler (as already explained);
e) in _main() handler, code is encapsulated in an script object and the script object is executed by "run script" command, which is a known technique to speed up the execution of script when saved as applet. (Actually this only makes the applet run as fast as compiled script run in editor. Without this, applet runs remarkably slower than run in editor.)
Hope this may be of some help.
Good luck,
H
on run
    _main()
end run
on _main()
    script o
        set FileName to "Blank.numbers"
        set ClientColumn to 2
        set CashFlowSheetName to "Cash Flow"
        tell application "Numbers"
            activate
            set WorkDocument to my makeAnNumbersDoc("Blank.nmbtemplate") -- creating a new file
            tell document WorkDocument's sheet 1
                set name to CashFlowSheetName
                delete table 1
            end tell
            set Clients to my GetListOfClients(FileName, ClientColumn) -- getting full list of the clients
            --return Clients
            repeat with i from 1 to count of Clients
                set FullCopy to my GetTable(FileName, item i of Clients, ClientColumn) -- choosing data
                --return FullCopy
                my MakeTable(WorkDocument, CashFlowSheetName, FullCopy, item i of Clients) -- making table with name of a client for every client
            end repeat
        end tell -- numbers
        return Clients -- test
    end script
    run script o -- # this will dramatically speed up the execution of script when saved as an applet
end _main
on MakeTable(WorkDocument, WorkSheet, DataList, Client)
    local utc_offset, rk, ck
    set utc_offset to time to GMT
    set Client to Client as string -- for safety
    tell application "Numbers"
        set rk to count DataList
        set ck to count DataList's item 1
        tell document WorkDocument's sheet WorkSheet
            make new table with properties {row count:rk, column count:ck, name:Client}
            tell table Client
                repeat with i from 1 to rk
                    repeat with j from 1 to ck
                        set t to DataList's item i's item j
                        if class of t is date then set t to t - utc_offset
                        set row i's cell j's value to t as text
                    end repeat
                end repeat
            end tell -- table
        end tell -- sheet
    end tell -- Numbers
end MakeTable
on GetListOfClients(FileName, TargetColumn)
    local FullListOfClient
    tell application "Numbers"
        --open (":Users:Master:Documents:" & FileName) as alias
        open ((path to documents folder from user domain as text) & FileName) as alias
        --open ((path to desktop as text) & FileName) as alias -- for test
        set FullListOfClient to {}
        tell document 1's sheet 1's table 1
            repeat with c in (get value of cell TargetColumn of rows 2 thru -1)
                set c to c's contents
                if c is not in FullListOfClient then set end of FullListOfClient to c
            end repeat
        end tell
    end tell
    return FullListOfClient
end GetListOfClients
on GetTable(DocName, TargetValue, TargetColumn)
    local CopyRow
    tell application "Numbers"
        tell document DocName's sheet 1's table 1
            set CopyRow to value of cell of rows whose cell TargetColumn's value = TargetValue
            set CopyRow's beginning to value of cell of row 1
            return CopyRow
        end tell
    end tell
end GetTable
--=====
Creates a new Numbers document from Blank.template
and returns its name.
on makeAnNumbersDoc(myTemplate)
    local t, n
    tell application "Numbers"
        set t to (((path to resource "Templates") as string) & myTemplate) as alias
        set n to count documents
        open t
        repeat until (count documents) > n
            delay 0.1
        end repeat
        return name of document 1
    end tell
end makeAnNumbersDoc

Similar Messages

  • When working with numbers twice now i've gotten a blue screen then restart on iphone 5s

    anyone else experiencing this issue? and any possible reason(s)/solution(s). it only seems to happen when working with Numbers. it has also happened on my ipad 2nd gen.

    Reset the device:
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings
    Then try Numbers.

  • APPLE TV DOES NOT WORK WITH NETFLIX

    APPLE TV DOES NOT WORK WITH NETFLIX, just a black screen and "Netflix is loading" message appears. I can´t even see Netflix´s home page or set up my account. Netflix is working fine on all other devices at home, but in Apple TV.
    I have tried the 8.8.8.8 DNS trick, the turn off procedure, the manual IP setting, but nothing....black screen still appears

    It started working.....!!!!!  (It seems someone back there is listening)
    I "forced" an upgrade, I mean it showed "AppleTV is updated", nevertheless I re-started the system using the "return to original configurations" option. Then it updated again by itself to a newer version....and started working perfectly.
    I have paired my apple wireless keyboard and it works fine, this way is easier to set up passwords or so (you can also do it with your remote).
    TIPS:
    I didn´t change any language or video quality configuration (scared to do so)
    I changed to ethernet (cable) instead of wireless
    My internet plan is 6 Megabytes (it was the same while it wasn't working)
    good luck!!

  • Apple Tv does not work with youtube and movies on iphone or ipad

    I am on my 2nd generation apple TV. Always worked with Youtube, my iphones and ipads and Netflix.
    I think it started about a month ago.  I can only use Netflix.
    If I try YouTube and select a video (even if small) it just keep spinning and never starts.
    The same thing happens with my video from iphone 5S, 5, and ipad 2.
    Than I went to my sons house with a Apple TV 3rd generation and different wifi,
    same thing happens, I can not show a video from my iPhone 5S.
    What is going on, did Apple TV change something?
    Is this a update that went wrong?
    (I have auto update and also checked manually to make sure have latest apple TV FW)
    (All iphone and ipads are latest FW).

    Hi pcorsaro,
    You may need to restore your Apple TV and see if the issue is resolved after that process:
    Apple TV (2nd and 3rd generation): Restoring your Apple TV
    http://support.apple.com/kb/ht4367
    Thanks for coming to the Apple Support Communities!
    Cheers,
    Braden

  • HT202157 My apple TV is not working with light flashing after up date

    My apple TV is not working with the light flashing after an up date, what can be done?

    same here macbok air 2012 appletv 3 bugs the **** out of me
    it just stops randomly after a "while"

  • My Apple TV is not working with my Macbook pro 13 inch mountain lion after Apple TV upgrade?

    My Apple TV is not working with my Macbook pro 13 inch mountain lion OS X 10.8.2 after Apple TV upgrade?
    I am getting an error message as soon as I try to connect my Apple TV
    An error occurred (-6722) while connecting to the AirPlay device “Apple TV”
    it was working fine however after the upgrde it is giving me the above error message

    same here macbok air 2012 appletv 3 bugs the **** out of me
    it just stops randomly after a "while"

  • My apple ID is not working with my apple store

    My apple ID is not working with my apple store

    I have the exact same problem as "Jan Olsen 1"
    I sent them feedback:
    "I was given a $25 iTunes gift card. 
    When trying to log on to my account, my password didn't work (though I entered the correct password THREE TIMES). 
    I requested help changing the password through an e-mail. Went through the process, changed the password.
    I successfully logged on to my account and entered the gift card information and was given a $25 credit.
    When I tried to buy mp3s, I was asked to enter my password - AGAIN. 
    I got one of the following messages each time I tried to enter my NEW password:
    'We could not complete your iTunes Store request. An unknown error occurred (5002).
    There was an error in the iTunes Store. Please try again later.'
    or
    'Verification is required.
    You must enter your AppleID and password, click Billing Info, and verify your payment information in order to make purchases.
    The Apple ID you entered couldn't be found or your password was incorrect. Please try again.'
    Don't know where to go from here."
    And then, just to log on to this forum, I had to enter my AppleID TWICE! Once, then again to verify my AppleID!
    Ridiculous! Frustrating!

  • HT5706 I am trying to set up Apple TV with my Uverse WiFi, but I get errors when entering my password.  One site said that Apple TV doesn't work with WPA which Uverse uses.  Is there anyway around this or will Uverse and Apple TV just not work together.

    Trying to set up Apple TV with ATT Uverse.  I get errors when trying to enter my WiFi password.  One site says that Apple TV doesn't work with Uverse because it uses WPA for encryption.  If true, does that mean Uverse subscribers cannot use Apple TV?

    Spurs63 wrote:
    does that mean Uverse subscribers cannot use Apple TV?
    No, that's a rather silly conclusion.
    There are two options:
    stop using the crappy router provided by the ISP.
    Physically connect the ATV to the router via Ethernet.

  • Outlook Email script won't work with Reader 9.1

    The attached form was designed in ES 8.2 and has worked fine with Reader 8.0. The "properties defaults" tab is set for Reader 9.0 or better. However, upon recent upgrade to Reader 9.1, the Outlook Email script stopped working. I'm new to Livecycle and scripts and was hoping that someone had an easy fix?

    okay thanks. One more question. What script is used to activate the "read receipt requested" function in Outlook?
    Date: Wed, 12 Aug 2009 12:23:13 -0600
    From: [email protected]
    To: [email protected]
    Subject: Outlook Email script won't work with Reader 9.1
    Interesting .....it sounds like an issue in Reader. From a code perspective everything is good .....the code tells Reader's email service to communicate with the mail client. This could be where the issue is.
    You may want to post your question on the Acrobat forum and see if they know of anything .....or you can report the issue to Support and have them look into it. Maybe something was introduced into the 9.1 version.
    From a Designer perspective all is good.
    Paul
    >

  • My Apple TV controller stopped working with my tv box. I changed battery. But the remote controller works in the store and it controles my iMac . What is the problem?

    My Apple TV controller stopped working with my tv box. I changed battery. But the remote controller works in the store and it controles my iMac . What is the problem?

    Hi Ron.
    Your Apple TV may have become paired with another remote. Hold the remote close to and pointed at the Apple TV, hold down the menu and Rewind buttons together for 6 seconds or until you see a broken chain icon on screen.

  • When is Apple going to start working with ADOBE and let us enjoy some videos and other things on our beloved iPads and iPhones?

    When is Apple going to start working with ADOBE and let us enjoy some videos and other things on our beloved iPads and iPhones?

    How totally clueless can one be?
    Apparently not more than you.
    Adobe has given up on mobile flash for any device. They announced this a while ago.
    They admitted mobile flash is a disaster and are jumping on the HTML 5 bandwagon.
    Adobe has moved on, why can't you?
    http://www.technobuffalo.com/mobile-devices/adobe-announces-the-end-of-flash-pla yer-for-mobile-devices/
    http://latimesblogs.latimes.com/technology/2011/11/adobe-to-end-mobile-flash-plu g-in-development.html

  • Why apple password did not work with my Ipod Touch

    why my apple password did not work with my Ipod Touch?

    Just where are you entering it?
    What happens when you try?

  • Apple Remote won't work with Logic

    I bought a new iMac (3.06 GHz Intel Core 2 Duo) and the Apple Remote won't work with Logic 8. It worked fine on my MacBook Pro.

    jazzmaniac, I did something by holding down two buttons on the remote for a few seconds. I guess that is called registering. But when I try to play a song file in Logic, Front Row pops up instead.
    I've searched the Internet and am finding little on this topic.

  • The airplay in apple tv doesn't work with my ipad

    I have problem the apple tv.
    Why the airplay in the apple tv doesn't work with my ipad,every time i set the password in the air play it won't allow and the (clear password) come out on the screen

    connect the atv to a tv which does support the resolution and then lower the resolution and then connect it with your tv once more

  • Why docking cradle with headset jack for apple iphone 5s not working with iPhone 5s headset

    why docking cradle with headset jack for apple iphone 5s not working with iPhone 5s headset.

    don't know.  what have you done to troubleshoot?

Maybe you are looking for

  • What is the best way of compressing a large 3 hour final cut file

    What is the best way of compressing a large 3 hour final cut file. I shot the play and it is in final cut and I rndered it so now I have a 22gb file that I need to put on a dvd . Any suggestions Thanks Macbook Pro 2.3 GHz Intel Core i7 with Final Cut

  • HT2729 Help pls! About to toss my ipod out the window!

    i recently downloaded a free video, kip moore's there's something about a truck to my itunes, yet no matter how many times I sync my ipod it won't transfer. What am I doing wrong? It's been years since I've put anything on here due to pc issues and I

  • Can i reinstall audio driver ?

    i m having some problems with audio and recording , i cant use stereo mix for recording ( i have posted regarding stereo mix earlier but didnt get any answer resolving the issue ) so i want to reinstall the realtek audio driver v. 6.0.1.7156 that i h

  • Deleting sections of a movie

    I imported a home movie into premier elements 10, and would like to delete some frames.  When I go to the scene line there is only 1 frame.  In the time line it extends for the whole movie. I do not see how you delete frames. Help.

  • Increase the resultset count in SSXA application

    Hi, I'm using UCM 11g + Site Studio, I'm coding in JSTL for my web application. I am calling many services like GET_SEARCH_RESULT etc. All these services are returning a resultset of 20 values. I have changed the setting by clicking the weblogic user