Text

改行コード変更(仮)

もう少しいい方法があるような気がする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
改行コードを調べて 改行コードを変更する
文字コードはUTF-8に変更する
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
##############################
#設定 デフォルトの改行コード
# 空の場合や
#1行だけで改行の無いテキストの場合
#この改行を適応する
#################################
set listNewLineChar to {"MacCR改行", "UnixLF改行", "WindowsCRLF改行"} as list
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#
set strTitle to ("選んでください") as text
set strPrompt to ("変更後の保存する改行コードを選んでください\nMac用の場合基本的には\nUnixLF改行を選んでください") as text
try
  set listResponse to (choose from list listNewLineChar with title strTitle with prompt strPrompt default items (item 2 of listNewLineChar) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしましたA"
else if (item 1 of listResponse) is {} then
return "キャンセルしましたB"
end if
set strResponse to (item 1 of listResponse) as text
#戻り値をキーにして値=値を取り出す
if strResponse is "MacCR改行" then
  set ocidSetNewLineChar to refMe's NSString's stringWithString:("\r")
else if strResponse is "UnixLF改行" then
  set ocidSetNewLineChar to refMe's NSString's stringWithString:("\n")
else if strResponse is "WindowsCRLF改行" then
  set ocidSetNewLineChar to refMe's NSString's stringWithString:("\r\n")
end if
##############################
#入力
##############################
#デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#
set listUTI to {"public.text"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("テキストファイルを選んでください") as text
try
  #ファイル選択
  set listFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles, showing package contents and multiple selections allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listFilePath) is false then
return "キャンセルしましたA"
else if listFilePath is {} then
return "キャンセルしましたB"
end if

##############################
#保存先
##############################
#保存先用にユーザーが選択したファイルの最初のエイリアスを取得
set aliasFirstFilePath to (item 1 of listFilePath) as alias
#パスにして
set strFirstFilePath to (POSIX path of aliasFirstFilePath) as text
set ocidFirstFilePathStr to (refMe's NSString's stringWithString:(strFirstFilePath))
set ocidFirstFilePath to ocidFirstFilePathStr's stringByStandardizingPath()
set ocidFirstFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFirstFilePath) isDirectory:false)
#ファイルの親階層ディレクトリを取得して
set ocidContainerDirPathURL to ocidFirstFilePathURL's URLByDeletingLastPathComponent()
#エイリアスとしてダイアログに渡す
set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
#
set strMes to "フォルダを選んでください" as text
set strPrompt to "フォルダを選択してください\n入力フォルダと同じフォルダを選択すると\n『上書き』になります" as text
try
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasContainerDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
#戻り値エイリアスをURLに
set strSaveDirPath to (POSIX path of aliasResponse) as text
set ocidSaveDirPathStr to (refMe's NSString's stringWithString:(strSaveDirPath))
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
#上書きチェック
if aliasContainerDirPath = aliasResponse then
log "同じフォルダに保存しようとしています"
  set strMes to "上書きを指定しました。\nファイルは上書きになります\nいいですか?" as text
  try
    ###ダイアログを前面に出す
    set strName to (name of current application) as text
    if strName is "osascript" then
      tell application "Finder" to activate
    else
      tell current application to activate
    end if
    #
    tell application (POSIX path of (path to frontmost application))
      set refResponse to (display alert ("【注意】:" & strMes) buttons {"OK", "処理中止"} default button "OK" cancel button "処理中止" as informational giving up after 20)
end tell
  on error
log "エラーしました"
return "エラーしました"
    error number -128
  end try
  if true is equal to (gave up of refResponse) then
return "時間切れですやりなおしてください"
    error number -128
  end if
  if "処理中止" is equal to (button returned of refResponse) then
return "処理を中止しました"
  end if
end if


##最初のファイル選択で選んだファイルの数だけ繰り返し
repeat with itemAliasFilePath in listFilePath
  #入力ファイルパス
  set aliasFilePath to itemAliasFilePath as alias
  #入力ファイルパス
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  #ファイル名
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  set strFileName to ocidFileName as text
  #ファイルのテキストを読み込み
  set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
  set ocidReadString to (item 1 of listResponse)
  if ocidReadString = (missing value) then
    set strFileName to ocidFilePathURL's lastPathComponent() as text
    set strMes to ("文字コードを判定出来ませんでした : " & strFileName & "\n処理を中止します") as text
display alert strMes
return
  end if
  ##############################
  #改行コード判定
  set ocidCrRange to (ocidReadString's rangeOfString:("\r"))'s location()
  set ocidLfRange to (ocidReadString's rangeOfString:("\n"))'s location()
  if ocidCrRange = refNSNotFound then
log "Mac改行は無い"
    if ocidLfRange = refNSNotFound then
log "Mac改行もUNIX改行は無い=改行の無い1行か空のテキスト"
      set ocidLength to ocidReadString's |length|
      if ocidLength = (refMe's NSNumber's numberWithInteger:0) then
log "空のテキスト"
        set ocidNewLineChar to ocidSetNewLineChar
      else
log "改行無しの1行テキスト"
        set ocidNewLineChar to ocidSetNewLineChar
      end if
    else
log "Mac改行無+UNIX改行あり=UNIX改行"
      set ocidNewLineChar to (refMe's NSString's stringWithString:("\n"))
    end if
  else
    if ocidLfRange = refNSNotFound then
log "MacがあるUNIX改行は無い=Mac改行"
      set ocidNewLineChar to (refMe's NSString's stringWithString:("\r"))
    else
log "Mac改行ある+UNIX改行あり=Windows改行"
      set ocidNewLineChar to (refMe's NSString's stringWithString:("\r\n"))
    end if
  end if
  ##############################
  ####改行コードを変更
  #改行を設定項目の改行コードに変更
  set ocidReadCFString to (ocidReadString's stringByReplacingOccurrencesOfString:(ocidNewLineChar) withString:(ocidSetNewLineChar))
  #出力先 保存先パス 選んだフォルダ+ファイル名
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName))
  #保存
  set listDone to (ocidReadCFString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
  if (item 1 of listDone) is true then
log "保存成功: " & strFileName
  else
log "エラーが発生しました: " & strFileName
  end if
end repeat

|

SJIS2UTF考え中


【スクリプトエディタで開く】|

  set ocidEncoding to refMe's CFString's CFStringConvertEncodingToNSStringEncoding(refMe's kCFStringEncodingShiftJIS)
  set ocidSjisStrings to (refMe's NSString's stringWithString:(jsonFontsExif))
  set ocidSjisData to (ocidSjisStrings's dataUsingEncoding:ocidEncoding)
  set ocidUTF8Strings to (refMe's NSString's alloc()'s initWithData:ocidSjisData encoding:(refMe's NSUTF8StringEncoding)) as text
  set ocidJsonData to (ocidUTF8Strings's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
  
  
  set listJsonData to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:(refMe's NSJSONReadingMutableContainers) |error|:(reference))
  set ocidJsonData to ((item 1 of listJsonData)'s objectAtIndex:0)

|

全角テキストを半角に

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#   com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set strText to "012345ABEDFGhijk+*-/$%&()"



###テキストに
set ocidText to (refMe's NSString's stringWithString:strText)
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)


log ocidResponseHalfwidth as text


(*
NSStringTransformToLatin
NSStringTransformLatinToArabic
NSStringTransformLatinToCyrillic
NSStringTransformLatinToGreek
NSStringTransformLatinToHangul
NSStringTransformLatinToHebrew
NSStringTransformLatinToHiragana
NSStringTransformLatinToKatakana
NSStringTransformLatinToThai
NSStringTransformHiraganaToKatakana
NSStringTransformMandarinToLatin
NSStringTransformStripDiacritics
NSStringTransformStripCombiningMarks
NSStringTransformFullwidthToHalfwidth
NSStringTransformToUnicodeName
NSStringTransformToXMLHex




*)

|

[アルファベット]character id



####基本

set numChrID to (id of "A")

-->(*65*)

set strNextChr to character id (numChrID + 1)

-->(*B*)



set numChrID to (id of "A")

set listAalphabet to {}


repeat 52 times

  if numChrID > 90 then

    set strChr to character id (numChrID - 26)

    set strChr to "A" & strChr

  else

    set strChr to character id numChrID

  end if

  copy strChr to end of listAalphabet

  set numChrID to numChrID + 1

end repeat


log listAalphabet

-->(*A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, AA, AB, AC, AD, AE, AF, AG, AH, AI, AJ, AK, AL, AM, AN, AO, AP, AQ, AR, AS, AT, AU, AV, AW, AX, AY, AZ*)

|

[Applescript]文字の置き換え

通常は


log doReplace("ABABBA", "B", "A")


to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace



NSStringだと
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

log doReplace("ABABBA", "B", "A")

to doReplace(argOrignalText, argSearchText, argReplaceText)
set ocidOrignalText to (current application's NSString)'s stringWithString:argOrignalText
set ocidReplasetText to ocidOrignalText's stringByReplacingOccurrencesOfString:argSearchText withString:argReplaceText
set strReplasetText to ocidReplasetText as text
return strReplasetText
end doReplace

|

[AppleScript]英数 半角 全角 キャピタライズ(先頭大文字)変換

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#error number -128
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSMutableString : a reference to refMe's NSMutableString


set strText to "ABC 123 defg HIJK 456 lmn"

set ocidStringM to refNSMutableString's alloc()'s initWithCapacity:0
ocidStringM's setString:strText

###全部小文字 ローケース
set ocidLowCaseText to ocidStringM's lowercaseString()
log ocidLowCaseText as text
log className() of ocidLowCaseText as text
(*abc 123 defg hijk 456 lmn*)
(*__NSCFString*)

####全部大文字 アッパーケース
set ocidUpperCaseText to ocidStringM's uppercaseString()
log ocidUpperCaseText as text
log className() of ocidUpperCaseText as text
(*ABC 123 DEFG HIJK 456 LMN*)
(*__NSCFString*)

####先頭大文字キャピタライズ
set ocidCapCaseText to ocidStringM's capitalizedString()
log ocidCapCaseText as text
log className() of ocidCapCaseText as text
(*Abc 123 Defg Hijk 456 Lmn*)
(*__NSCFString*)

|

[% Decode] stringByRemovingPercentEncoding %デコード

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString

## set text
set strURL to "http%3A%2F%2Ffoo%20bar%2F" as text

##Make NSString
set ocidNSString to objNSString's stringWithString:strURL
log ocidNSString as text
log ocidNSString's className() as text
-->(*__NSCFString*)

### Do Percent Encoding
set ocidEncodedURL to ocidNSString's stringByRemovingPercentEncoding()
log ocidEncodedURL as text
log ocidEncodedURL's className() as text
-->(*__NSCFString*)

return ocidEncodedURL as text
-->"http://foo bar/"




#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[AppleScript]テキストの改行を取る

テキストの改行を取る手っ取り早い方法

(*
スクリプト本体の改行は
¬
NOT SIGN
Unicode:U+00AC
UTF-8:C2AC
*)


set strTextWithReturn to "美しい日本語\n\nオープンタイプ\nフォント"

log strTextWithReturn
###文節事にリストにして
set listParagraph to every paragraph of strTextWithReturn as list

###リストを潰すと出来上がり
set strTextWithOutReturn to listParagraph as text

log strTextWithOutReturn



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

####ログ表示
doLogView()


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString

set ocidText to objNSString's stringWithString:"美しい日本語\n\nオープンタイプ\nフォント\n"

###改行コードを定義
set ocidNSCFCharacterSet to objMe's NSCharacterSet's characterSetWithCharactersInString:"\n"
log className() of ocidNSCFCharacterSet as text

###改行コードでArray=リスト化
set ocidTaggedPointerString to ocidText's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidTaggedPointerString as list
log className() of ocidTaggedPointerString as text

###リストをテキストに
set ocidOnewLineString to ocidTaggedPointerString's componentsJoinedByString:""
log ocidOnewLineString as text
log className() of ocidOnewLineString as text



#########################ログ表示
to doLogView()
tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[TEXT]テキストデータに行番号を入れる(3桁ゼロパディング)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#
006#
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009
010use AppleScript version "2.8"
011use framework "Foundation"
012use scripting additions
013
014property objMe : a reference to current application
015property objNSString : a reference to objMe's NSString
016property objNSMutableString : a reference to objMe's NSMutableString
017property objNSURL : a reference to objMe's NSURL
018property objNSMutableArray : a reference to objMe's NSMutableArray
019
020property objNSNotFound : a reference to 9.22337203685477E+18 + 5807
021
022set objFileManager to objMe's NSFileManager's defaultManager()
023
024
025####ダイアログで使うデフォルトロケーション
026set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(objMe's NSDesktopDirectory) inDomains:(objMe's NSUserDomainMask)) as alias
027
028####UTIリスト PDFのみ
029set listUTI to {"public.plain-text"} as list
030
031####ダイアログを出す
032set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (ocidUserDesktopPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
033
034set strFilePath to POSIX path of aliasFilePath as text
035####ドキュメントのパスをNSString
036set ocidFilePath to objNSString's stringWithString:strFilePath
037####ドキュメントのパスをNSURLに
038set ocidNSUrlPath to objNSURL's fileURLWithPath:ocidFilePath
039####ファイル名
040set ocidFileName to ocidNSUrlPath's lastPathComponent
041####拡張子を除いたファイル名
042set ocidPrefixName to ocidFileName's stringByDeletingPathExtension
043
044####ファイルを読み取る
045set strReadData to (objNSString's stringWithContentsOfFile:ocidFilePath encoding:(current application's NSUTF8StringEncoding) |error| :(missing value)) as text
046#####テキストの内容
047log strReadData
048################################################
049###可変テキスト初期化
050set ocidReadData to objNSMutableString's alloc()'s initWithCapacity:0
051###テキストデータを流し込み
052ocidReadData's setString:strReadData
053###↑文字数を数える
054set numCntSampleText to ocidReadData's |length|()
055###↑文字数全部でレンジにする
056set ocidNsRange to {location:0, |length|:numCntSampleText}
057###改行コード置き換え(CR/LF)
058ocidReadData's replaceOccurrencesOfString:"\r\n" withString:"\n" options:0 range:ocidNsRange
059###↑文字数を数える
060set numCntSampleText to ocidReadData's |length|()
061###↑文字数全部でレンジにする
062set ocidNsRange to {location:0, |length|:numCntSampleText}
063###改行コード置き換え(CR)
064ocidReadData's replaceOccurrencesOfString:"\r" withString:"\n" options:0 range:ocidNsRange
065###改行でリストにする
066set ocidReadDataNSArray to ocidReadData's componentsSeparatedByString:"\n"
067#####################
068set numLineNo to 0 as number
069set strOutData to "" as text
070#####
071repeat with objReadDataNSArray in ocidReadDataNSArray
072set strReadDataNSArray to objReadDataNSArray as text
073set numLineNo to numLineNo + 1 as number
074if numLineNo < 100 then
075set strZeroAdd to ("000" & numLineNo) as text
076set strLineNo to text -3 through -1 of strZeroAdd as text
077end if
078set strOutData to strOutData & strLineNo & "\t" as text
079set strOutData to strOutData & strReadDataNSArray & "\n" as text
080end repeat
081
082################################################
083###処理が終わったテキスト
084set ocidTempText to objNSString's stringWithString:strOutData
085######################
086###フォルダのパス
087###デスクトップフォルダのパス
088set aliasDirPath to (path to desktop folder from user domain) as alias
089set strDirPath to POSIX path of aliasDirPath as text
090####作りたいファイル名(ここは今日の日付)
091set strDateAndTimeJp to (my dateFormatterWithFormat:"yyyyMMdd-HHmm")
092set strDistFilePath to ("" & strDirPath & ocidPrefixName & "-" & strDateAndTimeJp & ".txt")
093
094###NSStringテキスト ファイルのパス
095set objDistFilePath to objNSString's stringWithString:strDistFilePath
096
097###ファイルを作る
098set boolMakeNewFile to (objFileManager's createFileAtPath:objDistFilePath |contents|:ocidTempText attributes:(missing value))
099####内容を書き込む UTF8で書き込む
100set boolFileWrite to (ocidTempText's writeToFile:objDistFilePath atomically:false encoding:(objMe's NSUTF8StringEncoding) |error| :(missing value))
101
102log boolMakeNewFile
103log boolFileWrite
104-->true or false
105
106
107
108
109
110###日付のサブ
111on dateFormatterWithFormat:classDateFormat
112set formatter to objMe's NSDateFormatter's alloc()'s init()
113formatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
114formatter's setDateFormat:(classDateFormat as string)
115set theString to (formatter's stringFromDate:(current date)) as text
116end dateFormatterWithFormat:
117
118
AppleScriptで生成しました

|

[AppleScript]英数 半角 全角 キャピタライズ(先頭大文字)変換

1:小文字を大文字に
2:大文字を小文字に
3:先頭大文字(キャピタライズ)に

ダウンロード - textlist.zip



1:小文字を大文字に

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7



set theText to "ABC 123 defg HIJK 456 lmn"



set listlowCaseList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} as list
set listCapList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} as list
set listText to every character of theText as list
set theResult to ""
repeat with theChar in listText
set numCount to 0
repeat with numChar from 1 to (count of listlowCaseList)
set theChkCar to (item numChar of listlowCaseList) as text
if theChkCar is (theChar as text) then
set theChar to (item numChar of listCapList) as text
else
set theChar to theChar
end if
end repeat
set theResult to (theResult & theChar) as text
end repeat



2:大文字を小文字に
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7


set theText to "ABC 123 defg HIJK 456 lmn"

set listlowCaseList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} as list
set listCapList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} as list
set listText to every character of theText as list
set theResult to ""
repeat with theChar in listText
set numCount to 0
repeat with numChar from 1 to (count of listCapList)
set theChkCar to (item numChar of listCapList) as text
if theChkCar is (theChar as text) then
set theChar to (item numChar of listlowCaseList) as text
else
set theChar to theChar
end if
end repeat
set theResult to (theResult & theChar) as text
end repeat



3:先頭大文字(キャピタライズ)に

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7


set theText to "ABC 123 defg HIJK 456 lmn"



set listlowCaseList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} as list
set listCapList to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} as list
set listText to every word of theText as list
set theResult to ""

repeat with theWord in listText
set theResultWord to ""
set numCount to 1
repeat with theChar in theWord
repeat with numChar from 1 to (count of listCapList)
set theChkCar to (item numChar of listCapList) as text
if theChkCar is (theChar as text) then
if numCount is 1 then
set theChar to (item numChar of listCapList) as text
else
set theChar to (item numChar of listlowCaseList) as text
end if
else
set theChar to theChar
end if
end repeat
set theResultWord to (theResultWord & theChar) as text
set numCount to numCount + 1
end repeat
set theResult to (theResult & " " & theResultWord) as text
end repeat

|

より以前の記事一覧

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom