Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:38:02+00:00 2026-05-22T20:38:02+00:00

I am having trouble creating a new table on a specific sheet using Applescript

  • 0

I am having trouble creating a new table on a specific sheet using Applescript unless the sheet I want insert the new table in is either new or current selected.
The general form of the code I am using is:

    tell application "Numbers"
    tell document 1
    tell sheet "This is the sheet I want to use"
    make new table with properties {name:"A new table"}
    end tell 
    end tell 
    end tell

Has anyone had any more success at achieving this? This looks to me like a bit of a problem for some advanced spreadsheet scripts in Numbers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:38:03+00:00Added an answer on May 22, 2026 at 8:38 pm

    OK. My first answer was accepted and could not be deleted, but was inadequate, so I have decided to edit it and add some code which really does solve the problem!

    This code comes via Yvan Koenig, who credits Nigel Garvey. Both are active on the applescript-users list, which is excellent, by the way, not least because of the activity of these two gentlemen, and so many other great AppleScripters.

    It relies on GUI scripting (which is always a horrible thing to have to fall back on, but it’s what we’ve got).

    The call to my activateGUIscripting() may cause a prompt for an admin password to appear. If you absolutely know that you have GUI scripting enabled (System Prefs->Universal Access->Enable Access for Assistive Devices) – then you can omit this line.

    The next two lines are just example calls, so you need a sheet called “Sheet 1” for these example calls to work.

    This will allow you to create a table in any sheet in any document, regardless of what is selected or frontmost.

    --EXAMPLE CALLS
    my activateGUIscripting()
    my selectsheet(1, "Sheet 1")
    my createNewTable(1, "Sheet 1", "myNewTable", 69, 13)
    
    --NUMBERS UTILS
    on createNewTable(dName, sName, newTable, nb_rows, nb_columns)
        tell application "Numbers" to tell document dName to tell sheet sName
            make new table with properties {name:newTable, row count:nb_rows, column count:nb_columns}
        end tell
    end createNewTable
    
    --=====
    on activateGUIscripting()
        (* to be sure than GUI scripting will be active *)
        tell application "System Events"
            if not (UI elements enabled) then set (UI elements enabled) to true
        end tell
    end activateGUIscripting
    --=====
    (*
    ==== Uses GUIscripting ====
     *)
    on selectsheet(theDoc, theSheet)
        script myScript
            property listeObjets : {}
            local maybe, targetSheetRow
            --+++++
            -- set log_report to "point 2 : " & (current date) & return
            --+++++
            tell application "Numbers"
                activate
                set theDoc to name of document theDoc (* useful if the passed value is a number *)
                tell document theDoc to set my listeObjets to name of sheets
            end tell -- "Numbers"…
    
            set maybe to theSheet is in my listeObjets
            set my listeObjets to {} -- So it will not be saved in the script *)
            if not maybe then
                error "The sheet “" & theSheet & "” is unavailable in the spreadsheet “" & theDoc & "” !"
            end if -- not maybe
    
            set maybe to 5 > (system attribute "sys2")
            tell application "System Events" to tell application process "Numbers"
                tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theDoc
                    if maybe then (* macOS X 10.4.x
    '(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
    The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
    Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
                        set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is theSheet))
                    else (* macOS X 10.5.x or higher *)
                        set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is theSheet)) or (value of first group's first static text is theSheet))
                    end if -- maybe…
                    (*
    Handler modified to accomodate sheets requiring a lot of time to get the focus
    *)
                    tell targetSheetRow to set value of attribute "AXSelected" to true
                    set cnt to 0
                    repeat (*
    Must way that Numbers becomes ready to receive the value *)
                        try
                            tell targetSheetRow to set value of attribute "AXDisclosing" to true
                            exit repeat
                        on error
                            set cnt to cnt + 1
                            delay 0.5 -- half a second
                        end try
                    end repeat
                end tell -- outline…
            end tell -- "System Events"…
            --+++++
            -- set log_report to log_report & "point 3, cnt = " & cnt & return & (current date) & return
            --+++++
            tell application "Numbers" to tell document theDoc to tell sheet theSheet to tell table 1
                with timeout of 20 * 60 seconds (*
    WITH this setting, the script will be able to wait 20 minutes for the asked value.
    I hope that the document will not be so huge that this delay prove to be too short. *)
                    value of cell "A1"
                end timeout
            end tell -- "Numbers"…
            --+++++
            -- set log_report to log_report & "point 4 : " & (current date) & return
            --+++++
            tell application "System Events" to tell application process "Numbers" (*
    Do the trick one more time to be sure that the sheet is open *)
                tell targetSheetRow to set value of attribute "AXDisclosing" to true
            end tell -- "System Events"…
            --+++++
            -- return log_report & "point 5 : " & (current date) & return
            --+++++
            (*
    End of the modified piece of code
    *)
        end script
        run myScript
    end selectsheet
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble creating a new model row in the database using ActiveRecord in
I am using the Microsoft.Practices.EnterpriseLibrary Database tools and I'm having trouble creating a new
I'm having a little trouble creating a new variable using a command within the
I'm using LINQ to Entities (not LINQ to SQL) and I'm having trouble creating
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I'm having some trouble with this code: //Creating a new ImageElement Struct ImageElement oElement
I'm pretty new with JQuery and I'm having trouble creating a behaviour that would
I'm having trouble creating a table and putting data pulled from SQL into it.
I'm having trouble creating a sharepoint project with .net 4.0. Using Visual Studio 2010,
I'm not sure if this syntax is Informix-specific, but I was having trouble creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.