I’m struggling to create a Folder Action to Open Number Application to run a script and save
Sounds easy but not having done this before its all very confusing
I have a AppleScript which I use currently but this means manually opening each CSV file, selecting the Table then running the Scrip and then Saving the File
I’d love to be able to do this with a Folder action, below is the script I run manually, if one of you clever people can help it would be appreciated.
CURRENT SCRIPT
tell application “Numbers”
activate
try
if not (exists document 1) then error number 1000
tell document 1
try
tell active sheet
set the selectedTable to ¬
(the first table whose class of selection range is range)
end tell
on error
error number 1001
end try
tell selectedTable
-- currently, use of headers and footers cannot be determined by a script.
-- make the following assumptions:
set usesHeaders to true -- assume 1 row and 1 column
set usesFooters to false -- assume 1 row
-- add a new column
add column after last column
set the summationColumn to the last column
-- set the formula of each cell of the summation column
tell summationColumn
if usesHeaders is true then
set startIndex to 2
else
set startIndex to 1
end if
repeat with i from startIndex to the count of cells
-- get the row of the cell
set thisRow to the row of cell i
-- determine range coordinates
set the rangeStart to the name of cell startIndex of thisRow
set the rangeEnd to the name of cell -2 of thisRow
-- create formula using SUM function
set the summationFormula to ¬
("=CEILING(" & rangeEnd & "," & 16 & ")") as string
-- set the formula to the cell
set the value of cell i to summationFormula
end repeat
end tell
end tell
tell selectedTable
-- currently, use of headers and footers cannot be determined by a script.
-- make the following assumptions:
set usesHeaders to true -- assume 1 row and 1 column
set usesFooters to false -- assume 1 row
-- add a new column
add column after last column
set the summationColumn to the last column
-- set the formula of each cell of the summation column
tell summationColumn
if usesHeaders is true then
set startIndex to 2
else
set startIndex to 1
end if
repeat with i from startIndex to the count of cells
-- get the row of the cell
set thisRow to the row of cell i
-- determine range coordinates
set the rangeStart to the name of cell startIndex of thisRow
set the rangeEnd to the name of cell -2 of thisRow
-- create formula using SUM function
set the summationFormula to ¬
("=SUM(" & rangeEnd & "/" & 16 & ")") as string
-- set the formula to the cell
set the value of cell i to summationFormula
end repeat
end tell
end tell
end tell
tell selectedTable
set Qty2 to "Qty2"
set Pr1 to "Print"
set the value of cell 1 of column "J" to Qty2
set the value of cell 1 of column "K" to Pr1
end tell
on error errorMessage number errorNumber
if errorNumber is 1000 then
set alertString to "MISSING RESOURCE"
set errorMessage to ¬
"Please create or open a document before running this script."
else if errorNumber is 1001 then
set alertString to "SELECTION ERROR"
set errorMessage to ¬
"Please select a table before running this script."
else
set alertString to "EXECUTION ERROR"
end if
if errorNumber is not -128 then
display alert alertString message errorMessage buttons {"Cancel"}
end if
error number -128
end try
end tell
Tried all variants but I’m unable to to selct the Table within Nimbers to run the Script, not even got as far as saving the files
Mark Casey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.