Hi Hiroto,
I have this script running, with one issue.
set tValues to my doThis(1) -- get values of the selection
if tValues is not "" then
activate
display dialog "Select the cells where you want to create the PopUp." & return & "After that, click on the 'OK' button."
my doThis(tValues) -- set the cell format of the new selection to "PopUp Menu" and set the values of the each menu item
tell application "Numbers" to display dialog "Done"
else
tell application "Numbers" to display dialog "You must select the cells in a table before running this script."
end if
on doThis(n)
tell application "Numbers"
set tTables to (tables of sheets of front document whose its selection range isnot missing value)
repeat with t in tTables-- t is a list of tables of a sheet
if contents of t is not {} then -- this list is not empty, it's the selected sheet
set activeTable to (get item 1 of t)
if n = 1 then return value of cells of selection range of activeTable-- return values of the selection
set format of (cells of selection range of activeTable) to pop up menu-- set the format to pop up menu
return my setValuePopUp(n) -- set value of each menu item
end if
end repeat
end tell
return ""
end doThis
on setValuePopUp(L)
tell application "System Events"
tell process "Numbers"
set frontmost to true
delay 0.3
set inspectorWindow to missing value
set tWindows to windows whose subrole is "AXFloatingWindow"
repeat with i in tWindows
if exists radio group 1 of i then
set inspectorWindow to i
exit repeat
end if
end repeat
if inspectorWindow is missing value then
keystroke "i" using {option down, command down} -- Show Inspector
else
performaction "AXRaise" of inspectorWindow-- raise the Inspector window to the front
end if
delay 0.3
tell window 1
clickradio button 4 of radio group 1 -- the "cell format" tab
delay 0.3
tell group 2 of group 1
set tTable to table 1 of scroll area 1
set tc to count rows of tTable
set lenL to (count L)
if tc < lenL then -- ** add menu items **
repeat until (count rows of tTable) = lenL
clickbutton 1 -- button [+]
end repeat
keystrokereturn-- validate the default name of the last menu item
else if tc > lenL then -- ** remove menu items **
repeat while exists row (lenL + 1) of tTable
select row (lenL + 1) of tTable
clickbutton 2 -- button [-]
end repeat
end if
tell tTable to repeat with i from 1 to lenL-- ** change value of each menu item **
set value of text field 1 of row i to item i of L
end repeat
end tell
end tell
end tell
end tell
end setValuePopUp
==============================
When the popup is created, if there is one header row, it adds "1" to the list of popup items, if there are two header rows, it adds "1", "2" to the list of popup items. What should i amend to remove this (i have two header rows in my sheet).
I would ideally like to add a "-" to the list (to represent nothing selected in the cell) as default i.e. top of the list (i could add the symbol to my source data but that would look untidy). At the moment, after running the script all cell values change to 1.
Oh, what would the best way to modify the script so it selects a specific cell range? At the moment i have to first select a column, then run the script, then select the source cells, then click ok on the dialog box before it does the magic.
Someone else will be running the script, and if its easy to change, i would prefer to have an absolute source cell range values so the user can just rund the script without any selection required.
If you can advise on this, that would be most helpful.