
AppleScriptでのメタ文字改行系の扱い
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | |
| 006 | AppleScriptのAS記法としての |
| 007 | メタ文字の仕様はこちら |
| 008 | https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW6 |
| 009 | |
| 010 | |
| 011 | |
| 012 | com.cocolog-nifty.quicktimer.icefloe *) |
| 013 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 014 | use AppleScript version "2.8" |
| 015 | use scripting additions |
| 016 | |
| 017 | |
| 018 | |
| 019 | set strTAB to (character id 9) as «class utf8» |
| 020 | set strLF to (character id 10) as «class utf8» |
| 021 | set strVT to (character id 11) as «class utf8» |
| 022 | set strFF to (character id 12) as «class utf8» |
| 023 | set strCR to (character id 13) as «class utf8» |
| 024 | set strSP to (character id 32) as «class utf8» |
| 025 | set strCRLF to (strCR & strLF) as «class utf8» |
| 026 | |
| 027 | set strTAB to (tab) as «class utf8» |
| 028 | set strLF to (linefeed) as «class utf8» |
| 029 | set strVT to strVT as «class utf8» |
| 030 | set strFF to strFF as «class utf8» |
| 031 | set strCR to (return) as «class utf8» |
| 032 | set strSP to (space) as «class utf8» |
| 033 | set strCRLF to (strCR & strLF) as «class utf8» |
| 034 | |
| 035 | set numTAB to (ASCII number of strTAB) as integer |
| 036 | set numLF to (ASCII number of strLF) as integer |
| 037 | set numVT to (ASCII number of strVT) as integer |
| 038 | set numFF to (ASCII number of strFF) as integer |
| 039 | set numCR to (ASCII number of strCR) as integer |
| 040 | set numSP to (ASCII number of strSP) as integer |
| 041 | set strCRLF to (numCR & " " & numLF) as text |
| 042 | |
| 043 | |
| 044 | set strTAB to doDec2HexPl(numTAB) |
| 045 | set strLF to doDec2HexPl(numLF) |
| 046 | set strVT to doDec2HexPl(numVT) |
| 047 | set strFF to doDec2HexPl(numFF) |
| 048 | set strCR to doDec2HexPl(numCR) |
| 049 | set numSP to doDec2HexPl(numSP) |
| 050 | set strCRLF to (strCR & " " & strLF) as text |
| 051 | |
| 052 | return strCRLF |
| 053 | |
| 054 | |
| 055 | |
| 056 | |
| 057 | |
| 058 | to 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 |
| 072 | end doDec2HexPl |
| AppleScriptで生成しました | |
