Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript with iWork Numbers (newbie)

Hello;


Never used Applescript here but seems from my reading it may be exactly what I need.


Basically I need something fairly simple with NUMBERS.


I need applescript to insert a Column after column A and add "name" as the value the top row (column header). This now becomes Column B.


Then I need the value of column B row 2 to be a concatenate value of Cell C2, D2, E2 with a space between each


Then I need to "FILL" all rows below in column B to concatenate the values of each row.

Example value of B3 would be C3, D3, E3 and F3, etc.


Can the "Fill" command be variable? I will be working with different spreadsheets and the number of rows will vary.


Ideally when a csv is added to a folder, i'd love a script to run and then save the file with the changes


However, it will save me a lot of time even if I can just open the numbers file and run a script.


Any advise will be appreciated.

APPLESCRIPT NEWBIE!

Mac Pro, Mac OS X (10.6.2), Quad Core Nehalem Mac Pro / IPhone 3G / Unibody Macbook

Posted on May 26, 2012 1:03 PM

Reply
Question marked as Best reply

Posted on May 27, 2012 8:23 AM

Hi,


Here is a script to start, test it in the AppleScript editor

-------------------------------------------------------------------------

setthisCSVFiletochoose file

if (thisCSVFile as string) ends with ".csv" then -- CSV only

setnumbersFiletotext 1 thru -5 of (thisCSVFileasstring)

tell application "Numbers"

open thisCSVFile

tell front document

tell table 1 of sheet 1

add column after column "A"

set value of cell 1 of column "B" to "name"

tell row 2 to set value of cell 2 to my convertListToText(get value of cells 3 thru 5) --C2, D2 and E2

repeat with i from 3 to (count row) --concatenate the values of each row

tell row i to set value of cell 2 to my convertListToText(get value of cells 3 thru -1) -- cell "C" trought the end of this row

end repeat

end tell

save as "LSDocumentTypeNativeDocument" in numbersFile -- save as ".numbers"

close saving no

end tell

end tell

endif


onconvertListToText(tList)

settidtotext item delimiters

settext item delimitersto " " -- separator = space

settValtotListastext -- convert AppleScript's list to string --> (value separated by space)

settext item delimiterstotid

return tVal

endconvertListToText

-------------------------------------------------------------------------



if it works as you want;

Here is the script for a folder action.

-------------------------------------------------------------------------

onadding folder items tothis_folderafter receivingadded_items

repeatwiththisCSVFileinadded_items

if (thisCSVFile as string) ends with ".csv" then -- CSV only

set numbersFile to text 1 thru -5 of (thisCSVFile as string)

tell application "Numbers"

open thisCSVFile

tell front document

tell table 1 of sheet 1

add column after column "A"

set value of cell 1 of column "B" to "name"

tell row 2 to set value of cell 2 to my convertListToText(get value of cells 3 thru 5) --C2, D2 and E2

repeat with i from 3 to (count row) --concatenate the values of each row

tell row i to set value of cell 2 to my convertListToText(get value of cells 3 thru -1) -- cell "C" trought the end of this row

end repeat

end tell

save as "LSDocumentTypeNativeDocument" in numbersFile -- save as ".numbers"

close saving no

end tell

end tell

end if

endrepeat

endadding folder items to


onconvertListToText(tList)

settidtotext item delimiters

settext item delimitersto " " -- separator = space

settValtotListastext -- convert AppleScript's list to string --> (value separated by space)

settext item delimiterstotid

return tVal

endconvertListToText

-------------------------------------------------------------------------

In Mac help --> AppleScript Help, type folder actions to learn how to enable "folder actions", how to assign a script to a folder, and where to save the script.

16 replies

Applescript with iWork Numbers (newbie)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.