Tuesday, September 27, 2022
  • Index
  •  » Code Exchange
  •  » List Creation, Iteration & Manipulation (fun little exercise)

#1 2022-09-07 09:18:59 am

ibrokemymac09
Member
Registered: 2022-07-15
Posts: 8

List Creation, Iteration & Manipulation (fun little exercise)

This fun little script displays all ASCII Characters in a display dialogue.

Applescript:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


set i to 255
set p to 0
set l to {}

repeat with x from 1 to i
   try
       set p to p + 1
       set l to l & ¬
           p
   on error
       set l to l & ¬
           " "
   end try
end repeat

set u to ""
set r to 0

repeat with y from 1 to (count l)
   try
       set r to r + 1
       set q to item r of l
       set u to u & ¬
           (ASCII character q) & ¬
           " "
   on error
       set u to u & ¬
           " "
   end try
   
end repeat
set h to items 150 through 152 of u as list


display dialog u & "

"
with title "ASCII Characters" buttons {(ASCII character 240)}

ASCII Dialog

Last edited by ibrokemymac09 (2022-09-07 09:38:20 am)

Offline

 

#2 2022-09-07 10:42:22 am

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

Re: List Creation, Iteration & Manipulation (fun little exercise)

Fun!

But your script is wildly inefficient.

Here is a slimmed down version

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set u to ""

repeat with x from 32 to 255 -- start at 32, all characters below are non-printing & control codes
   try
       set u to u & (character id x) & " "
   on error
       set u to u & " "
   end try
end repeat

-- set h to items 150 through 152 of u as list -- not sure what this did?

display dialog u & "" with title "UTF8 Characters" buttons {(character id 63743)}

...and here is a version that skips over all non-printing character codes

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set u to ""

set x to 32 -- chars 0 to 31 are control codes (i.e. invisible)
repeat until x > 255
   try
       set u to u & (character id x) & " "
   on error
       set u to u & " "
   end try
   set x to x + 1
   if x = 127 then set x to 160 -- chars 127 to 159 are more control codes (i.e. invisible)
end repeat

display dialog u & "" with title "UTF8 Characters" buttons {(character id 63743)}

Last edited by robertfern (2022-09-07 10:55:09 am)

Offline

 
  • Index
  •  » Code Exchange
  •  » List Creation, Iteration & Manipulation (fun little exercise)

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)