Tuesday, March 19, 2019

#1 2019-01-07 10:50:44 am

Adam239
Member
Registered: 2016-10-14
Posts: 80

Numbers - Format Column "Pop Up Menu" - How To Set Menu Items?

Hi There,

I am using this script to set format of a cell to pop up menu.
How can I specify what items are present in the list when the user clicks on the cell?

Thanks in advance for your help,
Adam

Applescript:

tell application "Numbers"
   activate
   tell the first table of the active sheet of document 1
       set the format of cell "A1" to pop up menu
   end tell
end tell


running Sierra 10.12.5

Offline

 

#2 2019-01-11 02:32:55 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4823

Re: Numbers - Format Column "Pop Up Menu" - How To Set Menu Items?

Hi.

It doesn't seem that pop up menus' contents are directly scriptable in the current version of numbers. However, I've had some success with the following, which uses GUI Scripting. Maybe it'll work for you too.

Applescript:

set menuItems to {"This", "That", "The Other", "Something Else Again"}

tell application "Numbers"
   activate
   tell the first table of the active sheet of document 1
       tell cell "A1"
           -- Set the cell value to the first menu item required. This also selects the cell.
           set value to item 1 of menuItems
           -- THEN set the cell format. This causes the menu to adopt the value just set as a single item instead of having the three default items.
           set the format to pop up menu
       end tell
   end tell
end tell

-- Use GUI Scripting to add the remaining items to the menu.
tell application "System Events"
   tell application process "Numbers"
       set frontmost to true
       tell window 1
           -- The inspector doesn't have to be visible, but its "Cell" pane does have to be selected.
           click radio button "Cell" of radio group 1
           -- Add the remaining items by clicking the "+" button and typing in the texts the required number of times.
           repeat with i from 2 to (count menuItems)
               click button 1 of group 1 of scroll area -1
               keystroke (item i of menuItems)
           end repeat
       end tell
   end tell
end tell


NG

Offline

 

#3 2019-01-11 03:17:12 am

Adam239
Member
Registered: 2016-10-14
Posts: 80

Re: Numbers - Format Column "Pop Up Menu" - How To Set Menu Items?

Thanks Nigel for your help here - much appreciated!
Seems weird that there wouldn't be some associated parameters with the format-type. Maybe I'll write a suggestion to Apple.


running Sierra 10.12.5

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)