テキストの各種文字の変換を行うAppleScriptです。
半角カタカナから全角への変換など、いまやテキストエディタの機能など用いる必要もなく、Cocoaの機能を呼び出すと手軽に行うことができます。
AppleScript名:文字種類変換(ASOC) |
— Created 2017-09-06 by Shane Stanley — Modified 2017-09-06 by Takaaki Naganoya use AppleScript version "2.5" — (10.12) or later use framework "Foundation" use scripting additions –http://piyocast.com/as/archives/4811 property NSString : a reference to current application’s NSString property NSStringTransformFullwidthToHalfwidth : a reference to current application’s NSStringTransformFullwidthToHalfwidth property NSStringTransformHiraganaToKatakana : a reference to current application’s NSStringTransformHiraganaToKatakana property NSStringTransformLatinToHiragana : a reference to current application’s NSStringTransformLatinToHiragana property NSStringTransformLatinToKatakana : a reference to current application’s NSStringTransformLatinToKatakana property NSStringTransformToUnicodeName : a reference to current application’s NSStringTransformToUnicodeName property NSStringTransformToXMLHex : a reference to current application’s NSStringTransformToXMLHex set a01 to hanToZen("トウキョウト") of me –> "トウキョウト"–Zenkaku (Full Width) set a02 to zenToHan(a01) of me –> "トウキョウト" –Hankaku (Half Width) set a03 to katakanaToHiraganaTo(a01) of me –> "とうきょうと" set a04 to hiraganaToKatakana(a03) of me –> "トウキョウト" set a05 to hiraganaToalphabet(a03) of me –> "toukyouto" set a06 to alphabetToHiragana(a05) of me –> "とうきょうと" set a07 to katakanaToAlphabet(a04) of me –> "toukyouto" set a08 to alphabetToKatakana(a07) of me –> "トウキョウト" set a09 to characterToUnicodeName("あ") of me –> "\\N{HIRAGANA LETTER A}" set a10 to unicodeNameToCharacter(a09) of me –> "あ" set a11 to stringToXMLHex("あ") of me –> "あ" set a12 to xmlHexTostring(a11) of me –> "あ" –半角→全角変換 on hanToZen(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformFullwidthToHalfwidth) |reverse|:true) as string end hanToZen –全角→半角変換 on zenToHan(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformFullwidthToHalfwidth) |reverse|:false) as string end zenToHan –ひらがな→カタカナ変換 on hiraganaToKatakana(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformHiraganaToKatakana) |reverse|:false) as string end hiraganaToKatakana –カタカナ→ひらがな変換 on katakanaToHiraganaTo(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformHiraganaToKatakana) |reverse|:true) as string end katakanaToHiraganaTo –ローマ字→ひらがな変換 on alphabetToHiragana(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformLatinToHiragana) |reverse|:false) as string end alphabetToHiragana –ひらがな→ローマ字変換 on hiraganaToalphabet(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformLatinToHiragana) |reverse|:true) as string end hiraganaToalphabet –ローマ字→カタカナ変換 on alphabetToKatakana(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformLatinToKatakana) |reverse|:false) as string end alphabetToKatakana –カタカナ→ローマ字変換 on katakanaToAlphabet(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformLatinToKatakana) |reverse|:true) as string end katakanaToAlphabet –文字→Unicode Name変換 on characterToUnicodeName(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformToUnicodeName) |reverse|:false) as string end characterToUnicodeName –Unicode Name→文字変換 on unicodeNameToCharacter(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformToUnicodeName) |reverse|:true) as string end unicodeNameToCharacter –文字→XML Hex変換 on stringToXMLHex(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformToXMLHex) |reverse|:false) as string end stringToXMLHex –XML Hex→文字変換 on xmlHexTostring(aStr) set aString to NSString’s stringWithString:aStr return (aString’s stringByApplyingTransform:(NSStringTransformToXMLHex) |reverse|:true) as string end xmlHexTostring |
More from my site
(Visited 547 times, 1 visits today)