20260531

AppleScriptでのメタ文字改行系の扱い

AppleScriptでのメタ文字改行系の扱い

NOTE記事一覧ですnote.com
 

【Safari・FireFox用Script Editorで開く】 |

CRLFVTFF.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
004(*
005
006AppleScriptのAS記法としての
007メタ文字の仕様はこちら
008https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW6
009
010
011
012com.cocolog-nifty.quicktimer.icefloe *)
013----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
014use AppleScript version "2.8"
015use scripting additions
016
017
018
019set strTAB to (character id 9) as «class utf8»
020set strLF to (character id 10) as «class utf8»
021set strVT to (character id 11) as «class utf8»
022set strFF to (character id 12) as «class utf8»
023set strCR to (character id 13) as «class utf8»
024set strSP to (character id 32) as «class utf8»
025set strCRLF to (strCR & strLF) as «class utf8»
026
027set strTAB to (tab) as «class utf8»
028set strLF to (linefeed) as «class utf8»
029set strVT to strVT as «class utf8»
030set strFF to strFF as «class utf8»
031set strCR to (return) as «class utf8»
032set strSP to (space) as «class utf8»
033set strCRLF to (strCR & strLF) as «class utf8»
034
035set numTAB to (ASCII number of strTAB) as integer
036set numLF to (ASCII number of strLF) as integer
037set numVT to (ASCII number of strVT) as integer
038set numFF to (ASCII number of strFF) as integer
039set numCR to (ASCII number of strCR) as integer
040set numSP to (ASCII number of strSP) as integer
041set strCRLF to (numCR & " " & numLF) as text
042
043
044set strTAB to doDec2HexPl(numTAB)
045set strLF to doDec2HexPl(numLF)
046set strVT to doDec2HexPl(numVT)
047set strFF to doDec2HexPl(numFF)
048set strCR to doDec2HexPl(numCR)
049set numSP to doDec2HexPl(numSP)
050set strCRLF to (strCR & " " & strLF) as text
051
052return strCRLF
053
054
055
056
057
058to doDec2HexPl(argDec)
059   set strSetValue to argDec as text
060   ##コマンド実行
061   set strCmd to ("printf \"%04X\\\n\", " & strSetValue & ";") as text
062   set strExec to ("/usr/bin/perl -e '" & strCmd & "'") as text
063   try
064      #コマンド実行
065      set strResponse to (do shell script strExec) as text
066   on error
067      log "osascript でエラーしました"
068      return false
069   end try
070   
071   return strResponse
072end doDec2HexPl
AppleScriptで生成しました