I thought about a simple idea to use Numbers functions in a simple way.
There I could use function name or type of method name and use parameters.
In this example I use 2 parameters and 2 function name.
You need to:
From the picture below you could see how my numbers table sheet looks like.
You need that to be able to run my code.
It takes 2 values from column A and B and return C based on D
The E column is only for description of the function.
The code use a repeat loop to make it small…
The column C contains Numbers function if that was not clear.
The document from Number could be extended to more functions.
-- its valueFromFunction:"BITXOR" withValues:{0, 0}
-- its valueFromFunction:"BITOR" withValues:{0, 0}
on valueFromFunction:functionName withValues:{numberValue1, numberValue2}
tell application "Numbers"
tell front document
tell sheet "Function"
tell table "Function Table"
repeat with i from 1 to 2
if (value of cell ("D" & i)) is functionName then
set value of cell ("A" & i) to numberValue1
set value of cell ("B" & i) to numberValue2
set theValue to value of cell ("C" & i)
end if
end repeat
return theValue
end tell
end tell
end tell
end tell
end valueFromFunction:withValues:
Here is a updated version.
-- its valueFromFunction:"BITAND" withValues:{1, 1}
-- its valueFromFunction:"BITOR" withValues:{1, 1}
-- its valueFromFunction:"BITXOR" withValues:{0, 1}
-- its valueFromFunction:"BITLSHIFT" withValues:{12, 3}
-- its valueFromFunction:"BITRSHIFT" withValues:{12, 3}
-- its valueFromFunction:"BIN2DEC" withValues:{"100111", 3}
-- its valueFromFunction:"BASETONUM" withValues:{"3F", 16}
-- its valueFromFunction:"BESSELJ" withValues:{25, 3}
-- its valueFromFunction:"BESSELY" withValues:{25, 3}
-- its valueFromFunction:"BIN2OCT" withValues:{"100111", 3} -- AppleScript convert octal to decimal
-- its valueFromFunction:"BIN2HEX" withValues:{"100111", 3} -- AppleScript convert hex to decimal
on valueFromFunction:functionName withValues:inputValues
set theValue to missing value
set inputValues to inputValues
set countInput to count inputValues
-- if (item 1 of inputValues)'s class is string then
-- return true
-- end if
tell application "Numbers"
tell front document
tell sheet "Function"
tell table "Function Table"
repeat with i from 1 to (count row) -- count the row in the table
if (value of cell ("D" & i) is functionName) then
-- inputValues of 1
if (countInput) = 1 then
set value of cell ("A" & i) to (item 1 of inputValues)
log value of cell ("A" & i) as string
set theValue to value of cell ("C" & i)
log value of cell ("C" & i) as string
end if
-- inputValues of 2
if (countInput = 2) then
set value of cell ("A" & i) to (item 1 of inputValues)
log value of cell ("A" & i) as string
set value of cell ("B" & i) to (item 2 of inputValues)
log value of cell ("B" & i) as string
set theValue to value of cell ("C" & i)
log value of cell ("C" & i) as string
end if
end if
end repeat
-- Return value
return theValue
end tell
end tell
end tell
end tell
end valueFromFunction:withValues:
Here is screenshot of the table in Numbers.
When you exchange data from a scriptable application you also realize its very slow 16 return values takes 0,6 seconds to execute.
On other hand, we also set 16x2=32 new values.
But its little fun to see Numbers update… (32 + 16) cells 