Skip navigation

Applescript to shift focus from sheet's pane to the table

801 Views 13 Replies Latest reply: Feb 11, 2013 6:56 AM by Hiroto RSS
fred6633 Calculating status...
Currently Being Moderated
Feb 10, 2013 8:12 AM

Cmd + Option + return shifts focus from the table to the sheet's pane. However, I haven't found a key that shifts focus back to the table. Therefore, I would appreciate an applescript that selects column A of the last row of the table, no matter which sheet has focus in the shift's pane.

 

Thanks

 

Fred

iMac, Mac OS X (10.6.7)
  • Jeff Shenk Level 4 Level 4 (2,000 points)

    As far as I can tell on my machine, Command Option Return just selects the active table on the object level.

     

    I suppose the next question might be, since a sheet may contain an arbitrary number of tables, how is the AppleScript supposed to determine to which table it is supposed to direct the command:

     

    set selection range to cell (-1) of column 1

  • Jeff Shenk Level 4 Level 4 (2,000 points)

    Did you wrap it in something like:

     

    tell application "Numbers"

              tell front table of front sheet of front document

                        set selection range to cell (-1) of column 1

              end tell

    end tell

  • Jeff Shenk Level 4 Level 4 (2,000 points)

    My apologies, I didn't check with multiple sheets; I made the erroneous assumption that if the term "front sheet" worked at all, it would detect the selected sheet.

     

    I don't think AppleScript has much awareness of the Sheets pane.

     

    I am going to play with another idea that I have, but if it works, it will be ugly.

  • Jeff Shenk Level 4 Level 4 (2,000 points)

    Doesn't work. I don't see any way to make AppleScript aware of what is selected in the Sheets pane.

  • Hiroto Level 5 Level 5 (4,815 points)

    Hello

     

    Try something like the script below. Numbers scripting support is sadly limited and this is the best I could think of.

    Tested with Numbers 2.05 under OSX 10.5.8.

     

    Regards,

    H

     

    main()
    on main()
        tell application "Numbers"
            activate
            set obj to my get_selected_container(document 1)
            tell obj
                if its class = table then
                    set selection range to row -1's cell 1
                else
                    tell application "Numbers"
                        display dialog "Only sheet \"" & obj's name & "\" is selected."
                    end tell
                end if
            end tell
        end tell
    end main
    
    on get_selected_container(doc)
        (*
            reference doc : source Numbers document
        *)
        tell application "System Events"
            tell process "Numbers"
                -- bring Numbers to front
                set frontmost to true
                
                -- bring target document window to front
                tell (window 1 whose title = doc's name) -- only based on window title (not so reliable)
                    perform action "AXRaise"
                end tell
                
                -- open new inspector window
                tell menu bar 1's menu bar item 9 -- view
                    if menu 1's menu item 11's enabled then
                        tell menu 1's menu item 11 -- new inspector
                            click
                        end tell
                    else
                        tell menu 1's menu item 10 --  inspector
                            click
                        end tell
                    end if
                end tell
                
                -- get sheet name and table name
                tell (window 1 whose subrole = "AXFloatingWindow") -- front inspector window
                    tell radio group 1
                        tell radio button 2 -- sheet
                            click
                        end tell
                    end tell
                    tell group 1
                        tell text field 2 -- name
                            set sheet_ to value
                        end tell
                    end tell
                    tell radio group 1
                        tell radio button 3 -- table
                            click
                        end tell
                    end tell
                    tell group 1
                        tell text field 4 -- name
                            set table_ to value
                        end tell
                    end tell
                    tell (button 1 whose subrole = "AXCloseButton") -- close
                        click
                    end tell
                end tell
                --return {sheet_, table_}
            end tell
        end tell
        
        -- return object specifier of table or sheet if table_ is ""
        tell application "Numbers"
            tell doc
                if table_ = "" then
                    return sheet sheet_
                else
                    return sheet sheet_'s table table_
                end if
            end tell
        end tell
    end get_selected_container
    
  • Hiroto Level 5 Level 5 (4,815 points)

    Hello

     

    The script below will select the cell in the first table if only the sheet is selected.

    Also I noticed the name main is somehow reserved in Automator and so replaced main() with _main() for use with it.

     

    Hope this helps,

    H

     

    _main()
    on _main()
        tell application "Numbers"
            activate
            set obj to my get_selected_container(document 1)
            tell obj
                if its class = table then
                    set selection range to row -1's cell 1
                else
                    tell table 1
                        set selection range to row -1's cell 1
                    end tell
                end if
            end tell
        end tell
    end _main
    
    on get_selected_container(doc)
        (*
            reference doc : source Numbers document
        *)
        tell application "System Events"
            tell process "Numbers"
                -- bring Numbers to front
                set frontmost to true
                
                -- bring target document window to front
                tell (window 1 whose title = doc's name) -- only based on window title (not so reliable)
                    perform action "AXRaise"
                end tell
                
                -- open new inspector window
                tell menu bar 1's menu bar item 9 -- view
                    if menu 1's menu item 11's enabled then
                        tell menu 1's menu item 11 -- new inspector
                            click
                        end tell
                    else
                        tell menu 1's menu item 10 --  inspector
                            click
                        end tell
                    end if
                end tell
                
                -- get sheet name and table name
                tell (window 1 whose subrole = "AXFloatingWindow") -- front inspector window
                    tell radio group 1
                        tell radio button 2 -- sheet
                            click
                        end tell
                    end tell
                    tell group 1
                        tell text field 2 -- name
                            set sheet_ to value
                        end tell
                    end tell
                    tell radio group 1
                        tell radio button 3 -- table
                            click
                        end tell
                    end tell
                    tell group 1
                        tell text field 4 -- name
                            set table_ to value
                        end tell
                    end tell
                    tell (button 1 whose subrole = "AXCloseButton") -- close
                        click
                    end tell
                end tell
                --return {sheet_, table_}
            end tell
        end tell
        
        -- return object specifier of table or sheet if table_ is ""
        tell application "Numbers"
            tell doc
                if table_ = "" then
                    return sheet sheet_
                else
                    return sheet sheet_'s table table_
                end if
            end tell
        end tell
    end get_selected_container
    
  • Hiroto Level 5 Level 5 (4,815 points)

    My pleasure! Glad to be of help.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.