Monday, March 1, 2021

#1 2021-01-18 02:16:16 pm

jhogue
Member
Registered: 2020-04-25
Posts: 9

How to use text Delimiters with Numbers

I'm trying to split some text separated with periods (IP addresses) that are listed in a Numbers spreadsheet but setting a Delimiter doesn't have an effect.

Here's my script:

set TestFile to "Macintosh HD:Users:Me:Documents:IP Addresses.numbers"
set MySheet to "Sheet1"

set x to 2

tell application "Numbers"
    set MyDoc to open TestFile
    tell MyDoc to tell sheet MySheet to tell table 1
       
        set TblRows to get row count
                set AppleScript's text item delimiters to "."

        --repeat with x from x to TblRows
        set MyData to value of cell ("A" & x)
       
        set IP_Net to items 1 thru 3 of MyData
        --end repeat

    end tell
end tell



With this script, using "29.52.135.92 as test data, IP_Net will equal {"2","9","."}
I want {"29","52","135"}

If I remove "AppleScript's" from the line "set AppleScript's text item delimiters to "."" I just get an error.

Is there anyway to use delimiter's in Numbers?
Or is there a different way to do this?


I'm using Big Sur and the latest version of Numbers.

Thanks in advance!

Jason

Offline

 

#2 2021-01-18 02:29:10 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11739
Website

Re: How to use text Delimiters with Numbers

Applescript:

set IP_Net to items 1 thru 3 of MyData

are the first three characters, but you want the text items

Applescript:

set IP_Net to text items 1 thru 3 of MyData


regards

Stefan

Offline

 

#3 2021-01-18 02:46:05 pm

jhogue
Member
Registered: 2020-04-25
Posts: 9

Re: How to use text Delimiters with Numbers

Even with that I get the same result :-(

Jason

Offline

 

#4 2021-01-18 04:07:51 pm

robertfern
Member
Registered: 2011-11-29
Posts: 108

Re: How to use text Delimiters with Numbers

It seems that text items only works outside the tell block as "Keynote" doesn't understand and only returns individual characters

Applescript:

set MySheet to "Sheet1"

set x to 2
set text item delimiters to "."
tell application "Numbers"
   set MyDoc to document 1
   tell MyDoc to tell sheet MySheet to tell table 1
       
       set TblRows to get row count
       set AppleScript's text item delimiters to "."
       
       --repeat with x from x to TblRows
       set MyData to value of cell ("A" & x)
       --end repeat
       
   end tell
end tell
set IP_Net to text items 1 thru 3 of MyData -- outside of tell block

oddly, even if I used a "tell me" line inside the tell block, it still doesn't work

Applescript:

set MySheet to "Sheet1"

set x to 2
set text item delimiters to "."
tell application "Numbers"
   set MyDoc to document 1
   tell MyDoc to tell sheet MySheet to tell table 1
       
       set TblRows to get row count
       set AppleScript's text item delimiters to "."
       
       --repeat with x from x to TblRows
       set MyData to value of cell ("A" & x)
       tell me to set IP_Net to text items 1 thru 3 of MyData -- THIS DON'T WORK
       --end repeat
       
   end tell
end tell

*EDIT* -- I just figured out by reading the dictionary for Numbers that "text item" is a different thing in Numbers that to pure AppleScript.

Last edited by robertfern (2021-01-18 04:28:07 pm)

Offline

 

#5 2021-01-18 04:08:43 pm

akim
Member
Registered: 2010-04-04
Posts: 116

Re: How to use text Delimiters with Numbers

Calling a subroutine or function from the script such as

Applescript:

set IP_Net to my getTextItemsOf:MyData

and adding the following subroutine or function

Applescript:

on getTextItemsOf:MyData
   set AppleScript's text item delimiters to "."
   set IP_Net to text items 1 thru 3 of MyData
end getTextItemsOf:

resolved the dilemma for me.

For reasons not clear to me, Numbers.app interprets the term text items differently than does AppleScript's Text Item Delimiters.

Offline

 

#6 2021-01-18 05:04:22 pm

jhogue
Member
Registered: 2020-04-25
Posts: 9

Re: How to use text Delimiters with Numbers

Fantastic !!!
This works perfectly!
You just made my life easier ;-)

Jason

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)