Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

AppleScript: Using Unicode the Sneaky Way System
In my daily workflow, I often use AppleScript. Sometimes I need to use symbols in, say, TextEdit. Usually, you would open the Character Palette. But I found an interesting way to use AppleScript's power to insert Unicode characters using the «data» format in AppleScript.

AppleScript will let you use the «data» format for a lot of things. Images, for instance, can be stored in here. But since you're looking to use Unicode, we'll look at what AppleScript can do to make Unicode strings.

First of all, you need to know that Unicode text in AppleScript's «data» format is «data utxt». That means you have a blank, raw Unicode string. So after utxt, you can use the 4-digit code for the character. So, try this script in AppleScript Editor:

«data utxt2756»

That'll return «data utxt2756» literally, so, we need to add "as Unicode text" after, like this:

«data utxt2756» as Unicode text

You can do a lot of stuff with that string now.

[crarko adds: I tested this (in 10.6), and it works as described.]
    •    
  • Currently 2.37 / 5
  You rated: 3 / 5 (19 votes cast)
 
[8,176 views]  

AppleScript: Using Unicode the Sneaky Way | 11 comments | Create New Account
Click here to return to the 'AppleScript: Using Unicode the Sneaky Way' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript: Using Unicode the Sneaky Way
Authored by: Sesquipedalian on May 24, '10 08:06:05AM
Er, AppleScript has been entirely based on Unicode since Leopard came out. If you want to use Unicode characters, just insert the characters themselves into you script.

See http://www.macosxautomation.com/applescript/features/unicode.html

[ Reply to This | # ]

AppleScript: Using Unicode the Sneaky Way
Authored by: renaultssoftware on May 25, '10 03:46:37AM

The whole point of using the raw stuff is to avoid having to insert it yourself if you're a Unicode genius.



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: Sesquipedalian on May 26, '10 10:20:40AM

Wait, are you telling me you have the entire Unicode table memorized? If so, I stand in awe of your mnemonic abilities! If not, you presumably use the Character Palette to find out the Unicode values of the characters you want, so why not just double-click on the character to insert it into the script rather than typing in the entire raw data construct?



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: renaultssoftware on May 27, '10 04:19:43AM

I often memorize pertinent character's IDs. Like 2756 is a black diamond with an X thru it. Or whatnot? It helps me, and it helps someone who has to type Apple's modifier keys or something.



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: sprale on May 25, '10 07:32:17AM

I'm still stuck supporting both Tiger and Leopard, so I have to continue to the old fashioned way for now, though it's nice to know I can simplify things when it's time for me to drop Tiger...



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: asadKing on May 24, '10 08:13:38AM

you mension holding images in the <<data>> how do I do that?



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: renaultssoftware on May 25, '10 03:52:08AM
This is one thing that Adium uses for a picture:
«data TIFF00FFFF»
Weird enuff for ya?
Edited on May 25, '10 03:56:04AM by renaultssoftware


[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: brh on May 24, '10 08:05:53PM
"Usually, you would open the Character Palette." Wait, what? If you know the Unicode value, I would say that usually you would just use the Unicode Hex Input method… Assuming you know the value (you need to for this hint), that seems much quicker than hunting around in the character palette or doing some Applescript trickery…

[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: hynek on May 24, '10 11:37:02PM
Since AppleScript 2.0 all text is Unicode.
So if you don't want to write your text in hex like this:
set myText to «data utxt00680065006C006C006F» as Unicode text

Try this for special characters:
set myText to character id 37329 & " <-> " & id of "金"

[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: renaultssoftware on May 27, '10 04:16:58AM

I know you can do that. But this is the "sneaky way" I use because it's a bit time-consuming to hunt down characters in the Char Palette. Besides, I can concatenate text in AppleScript, and do all that wonderful stuff in text editors. A Unicode geek would like this hint a lot, I can tell.



[ Reply to This | # ]
AppleScript: Using Unicode the Sneaky Way
Authored by: mantrid on May 27, '10 07:44:34AM

What exactly do you mean by "I found an intersting way"? Unicode savvy AppleScripters have been using this trick (within its limitations) for a while, in particular before the improved unicode support in Leopard's AppleScript so if you "found" it on a web page, you should credit the source. If you worked it out yourself, a quick search would have told you that the method is already known, which makes "I found" a little presumptuous.



[ Reply to This | # ]