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
Numbers 09-OTHER, OS X Mountain Lion (10.8.4)