ReadMe

記事の内容によっては、執筆時の内容が現在の事実と異なったりする場合があります。
内容の真偽は、ご自分でご確認ください。
また
プログラム類につきましても、意図する動作をするのか?は
ご自身でご確認の上、ご自身の責任において実行してください。

お問合せ等ありましたら
本記事のコメント欄にコメントを残してください。
返答のいる内容については、メールアドレス等の連絡先情報をお忘れなく。
ギフト歓迎ですーー>ドトール イーギフト

【コーヒーギフトの送信先アドレスはこちら】



本BLOGの記事は
個別ページにおいて
別途指定していない記事やコンテンツは
CC0 1.0 全世界 (CC0 1.0)
パブリック・ドメインを選択しています。
(外部ライブラリやマテリアル等、個別のライセンス指定がある物もあります。留意ください)
https://creativecommons.org/publicdomain/zero/1.0/deed.ja



引用流用するときに記載してくれたら嬉しいですが、CC0 1.0を選択していますので必要はありません。



| | コメント (0) | トラックバック (0)

テキストファイルエンコード変換


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
テキストファイル
TSVやCSV javascriptの文字コードをまとめて変換します
選択ファイルと同じフォルダを保存先に選ぶと上書きになります

*)
----+----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

##############################
#入力
##############################
#ダイアログ
tell current application
  set strName to name as text
end tell
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
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 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 listFilePath is (missing value) then
return "選んでください"
end if
##############################
#エンコード選択
##############################
set recordEnc to {|NSISO2022JPStringEncoding|:(refMe's NSISO2022JPStringEncoding), |NSJapaneseEUCStringEncoding|:(refMe's NSJapaneseEUCStringEncoding), |NSShiftJISStringEncoding|:(refMe's NSShiftJISStringEncoding), |NSUTF8StringEncoding|:(refMe's NSUTF8StringEncoding), |NSUTF16LittleEndianStringEncoding|:(refMe's NSUTF16LittleEndianStringEncoding), |NSUTF16StringEncoding|:(refMe's NSUTF16StringEncoding), |NSUnicodeStringEncoding|:(refMe's NSUnicodeStringEncoding), |NSUTF32LittleEndianStringEncoding|:(refMe's NSUTF32LittleEndianStringEncoding), |NSUTF32StringEncoding|:(refMe's NSUTF32StringEncoding)} as record
set ocidEncDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidEncDict's setDictionary:(recordEnc)
set ocidAllKey to ocidEncDict's allKeys()
#
set ocidSortedAllKey to ocidAllKey's sortedArrayUsingSelector:("localizedStandardCompare:")
set listSortedAllKey to ocidSortedAllKey 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 ("保存エンコードを選んでください\nUTF16-32は通常LE=LittleEndianを選んでください") as text
try
  set listResponse to (choose from list listSortedAllKey with title strTitle with prompt strPrompt default items (item 5 of listSortedAllKey) 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
set ocidSetEnc to (ocidEncDict's valueForKey:(strResponse))

##############################
#保存先
##############################
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
  #ダイアログ
  tell current application
    set strName to name as text
  end tell
  #スクリプトメニューから実行したら
  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
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)
#

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 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
return "文字コードを判定出来ませんでした : " & strFileName
  end if
  
  ##############################
  #出力先 保存先パス
  ##############################
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName))
  
  ##############################
  #保存
  ##############################
  set listDone to (ocidReadString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidSetEnc) |error|:(reference))
  
end repeat






|

Pantone Color Swatch

同封12種類
PANTONE Color Bridge Coated V5
PANTONE Color Bridge Uncoated V5
PANTONE Formula Guide Solid Coated V5
PANTONE Formula Guide Solid Uncoated V5
PANTONE GoeBridge Coated
PANTONE GoeGuide Coated
PANTONE GoeGuide Uncoated
PANTONE Plus CMYK Coated
PANTONE Plus CMYK Uncoated
PANTONE Plus Metallics coated
PANTONE Plus Pastels and Neons Coated
PANTONE Plus Pastels and Neons Uncoated



ダウンロード - pantone.zip




面倒でも開くから1づつ読み込んだ方いいようです
20240302070555_1176x552

|

[8BIT2HEX]8bitカラー値をhex値に変換

8bitカラー値をhex値に変換
record--> NSDictionaryから値を参照する方式(現時点で一番速い
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-c6e523.html

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

set strRno to "0"
set strGno to "128"
set strBno to "255"

# printfを使う
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strRno & "\"") as text
set strRhex to (do shell script strCommandText)
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strGno & "\"") as text
set strGhex to (do shell script strCommandText)
set strCommandText to ("/usr/bin/printf \"%02X\" \"" & strBno & "\"") as text
set strBhex to (do shell script strCommandText)
set strColorHex to (strRhex & strGhex & strBhex) as text
-->"0080FF"

# printfを使う
set strCommandText to ("/usr/bin/printf \"%02X%02X%02X\" `/bin/echo \"" & strRno & " " & strGno & " " & strBno & "\"`") as text
set strBhex to (do shell script strCommandText)
--> "0080FF"

# perlを使う
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strRno & ")'") as text
set strRhex to (do shell script strCommandText) as text
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strGno & ")'") as text
set strGhex to (do shell script strCommandText) as text
set strCommandText to ("/usr/bin/perl -e 'printf(\"%02X\"," & strBno & ")'") as text
set strBhex to (do shell script strCommandText) as text
set strColorHex to (strRhex & strGhex & strBhex) as text
-->"0080FF"

# python3を使う
set strRGB8Bit to (strRno & strGno & strBno) as text
set strCommandText to ("/usr/bin/python3 -c \"print('%02X%02X%02X' % (" & strRno & "," & strGno & "," & strBno & "))\"") as text
set strRGBHEX to (do shell script strCommandText) as text
-->"0080FF"

|

8bitカラー値をhex値に変換


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

#!/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


log getHex(0)
-->(*00*)
log getHex(128)
-->(*80*)
log getHex(255)
-->(*FF*)


##############################
#サブ
##############################
to getHex(arg8BitNum)
  set record8Bit2Hex to {|0|:"00", |1|:"01", |2|:"02", |3|:"03", |4|:"04", |5|:"05", |6|:"06", |7|:"07", |8|:"08", |9|:"09", |10|:"0A", |11|:"0B", |12|:"0C", |13|:"0D", |14|:"0E", |15|:"0F", |16|:"10", |17|:"11", |18|:"12", |19|:"13", |20|:"14", |21|:"15", |22|:"16", |23|:"17", |24|:"18", |25|:"19", |26|:"1A", |27|:"1B", |28|:"1C", |29|:"1D", |30|:"1E", |31|:"1F", |32|:"20", |33|:"21", |34|:"22", |35|:"23", |36|:"24", |37|:"25", |38|:"26", |39|:"27", |40|:"28", |41|:"29", |42|:"2A", |43|:"2B", |44|:"2C", |45|:"2D", |46|:"2E", |47|:"2F", |48|:"30", |49|:"31", |50|:"32", |51|:"33", |52|:"34", |53|:"35", |54|:"36", |55|:"37", |56|:"38", |57|:"39", |58|:"3A", |59|:"3B", |60|:"3C", |61|:"3D", |62|:"3E", |63|:"3F", |64|:"40", |65|:"41", |66|:"42", |67|:"43", |68|:"44", |69|:"45", |70|:"46", |71|:"47", |72|:"48", |73|:"49", |74|:"4A", |75|:"4B", |76|:"4C", |77|:"4D", |78|:"4E", |79|:"4F", |80|:"50", |81|:"51", |82|:"52", |83|:"53", |84|:"54", |85|:"55", |86|:"56", |87|:"57", |88|:"58", |89|:"59", |90|:"5A", |91|:"5B", |92|:"5C", |93|:"5D", |94|:"5E", |95|:"5F", |96|:"60", |97|:"61", |98|:"62", |99|:"63", |100|:"64", |101|:"65", |102|:"66", |103|:"67", |104|:"68", |105|:"69", |106|:"6A", |107|:"6B", |108|:"6C", |109|:"6D", |110|:"6E", |111|:"6F", |112|:"70", |113|:"71", |114|:"72", |115|:"73", |116|:"74", |117|:"75", |118|:"76", |119|:"77", |120|:"78", |121|:"79", |122|:"7A", |123|:"7B", |124|:"7C", |125|:"7D", |126|:"7E", |127|:"7F", |128|:"80", |129|:"81", |130|:"82", |131|:"83", |132|:"84", |133|:"85", |134|:"86", |135|:"87", |136|:"88", |137|:"89", |138|:"8A", |139|:"8B", |140|:"8C", |141|:"8D", |142|:"8E", |143|:"8F", |144|:"90", |145|:"91", |146|:"92", |147|:"93", |148|:"94", |149|:"95", |150|:"96", |151|:"97", |152|:"98", |153|:"99", |154|:"9A", |155|:"9B", |156|:"9C", |157|:"9D", |158|:"9E", |159|:"9F", |160|:"A0", |161|:"A1", |162|:"A2", |163|:"A3", |164|:"A4", |165|:"A5", |166|:"A6", |167|:"A7", |168|:"A8", |169|:"A9", |170|:"AA", |171|:"AB", |172|:"AC", |173|:"AD", |174|:"AE", |175|:"AF", |176|:"B0", |177|:"B1", |178|:"B2", |179|:"B3", |180|:"B4", |181|:"B5", |182|:"B6", |183|:"B7", |184|:"B8", |185|:"B9", |186|:"BA", |187|:"BB", |188|:"BC", |189|:"BD", |190|:"BE", |191|:"BF", |192|:"C0", |193|:"C1", |194|:"C2", |195|:"C3", |196|:"C4", |197|:"C5", |198|:"C6", |199|:"C7", |200|:"C8", |201|:"C9", |202|:"CA", |203|:"CB", |204|:"CC", |205|:"CD", |206|:"CE", |207|:"CF", |208|:"D0", |209|:"D1", |210|:"D2", |211|:"D3", |212|:"D4", |213|:"D5", |214|:"D6", |215|:"D7", |216|:"D8", |217|:"D9", |218|:"DA", |219|:"DB", |220|:"DC", |221|:"DD", |222|:"DE", |223|:"DF", |224|:"E0", |225|:"E1", |226|:"E2", |227|:"E3", |228|:"E4", |229|:"E5", |230|:"E6", |231|:"E7", |232|:"E8", |233|:"E9", |234|:"EA", |235|:"EB", |236|:"EC", |237|:"ED", |238|:"EE", |239|:"EF", |240|:"F0", |241|:"F1", |242|:"F2", |243|:"F3", |244|:"F4", |245|:"F5", |246|:"F6", |247|:"F7", |248|:"F8", |249|:"F9", |250|:"FA", |251|:"FB", |252|:"FC", |253|:"FD", |254|:"FE", |255|:"FF"} as record
  set ocid8Bit2HexDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocid8Bit2HexDict's setDictionary:(record8Bit2Hex)
  set str8BitNum to arg8BitNum as string
  set ocidValue to (ocid8Bit2HexDict's valueForKey:(str8BitNum))
  set strValue to ocidValue as text
return strValue
end getHex

|

CSV2TSV 修正


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# CSV2TSV
# クオテーション有りのCSVの処理を修正した
# 文字コードが判定出来ない場合停止するようにした
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

###Wクリックで起動した場合
on run
  ###ダイアログ
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  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 listUTI to {"public.comma-separated-values-text"}
  set strMes to ("ファイルを選んでください") as text
  set strPrompt to ("ファイルを選んでください") as text
  try
    ### ファイル選択時
    set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
  on error
log "エラーしました"
return "エラーしました"
  end try
  if listAliasFilePath is {} then
return "選んでください"
  end if
open listAliasFilePath
end run


on open listAliasFilePath
  
  repeat with itemAliasFilePath in listAliasFilePath
    ##パス
    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 ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
    set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("tsv"))
    
    #ファイルのテキストを読み込み
    # set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
    # set ocidReadString to (item 1 of listResponse)
    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
return "文字コードを判定出来ませんでした : " & strFileName
    end if
    #出力用のテキスト
    set ocidOutPutString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
    #ユニックス改行の数を調べて
    set ocidCharSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:("\n"))
    set ocidLineArrayN to (ocidReadString's componentsSeparatedByCharactersInSet:(ocidCharSet))
    set numCntLineNoN to (count of ocidLineArrayN) as integer
    #改行キャラクタ\nと\rの数をそれぞれ数えて
    set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
    set ocidLineArrayNL to (ocidReadString's componentsSeparatedByCharactersInSet:(ocidCharSet))
    set numCntLineNoNL to (count of ocidLineArrayNL) as integer
    #改行方式でテキストを行毎処理としてリストにする
    #UNIX改行の数と改行キャラクタの数が同じならUNIX改行
    
    if numCntLineNoN = numCntLineNoNL then
log "UNIX改行です"
      set strNewlineCharacter to ("\n") as text
      set ocidLineArray to ocidLineArrayN
      #改行がない1行ならMacの可能性が高い
    else if numCntLineNoN = 1 then
      #\rが複数あるならまぁMac改行で間違い無いでしょ
      if numCntLineNoNL > 1 then
log "Mac改行です"
        set strNewlineCharacter to ("\r") as text
        set ocidCharSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:(strNewlineCharacter))
        set ocidLineArray to (ocidReadString's componentsSeparatedByCharactersInSet:(ocidCharSet))
      else
return "処理中止"
      end if
      #UNIX改行の数より改行キャラクタの数が多いならWIN改行
    else if numCntLineNoNL > numCntLineNoN then
log "Windows改行です"
      #WINDOWS改行はUNIX改行に置換してからArray処理する
      set strNewlineCharacter to ("\r\n") as text
      set ocidWindowsString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
(ocidWindowsString's setString:(ocidReadString))
      set ocidReadString to (ocidWindowsString's stringByReplacingOccurrencesOfString:(strNewlineCharacter) withString:("\n"))
      set ocidCharSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:(strNewlineCharacter))
      set ocidLineArray to (ocidReadString's componentsSeparatedByCharactersInSet:(ocidCharSet))
    else
return "処理中止"
    end if
    #クオテーション処理の有無を調べる
    set ocidFirstLine to ocidLineArray's firstObject()
    set ocidRange to refMe's NSMakeRange(0, 1)
    set strFirstChar to (ocidFirstLine's substringWithRange:(ocidRange)) as text
    if strFirstChar is "\"" then
log "クオテーション形式のCSV"
      set strSchar to ("\",\"") as text
    else
log "通常のCSV"
      set strSchar to (",") as text
    end if
    #行毎の処理
    repeat with itemLineString in ocidLineArray
      if (itemLineString as text) is "" then
        ##空行=最後の行に改行がある場合は終了
        exit repeat
      end if
      #行のテキストを可変テキストに入れて
      set ocidLineString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
(ocidLineString's setString:(itemLineString))
      #区切り文字でタブに置換
      set ocidTabLineString to (ocidLineString's stringByReplacingOccurrencesOfString:(strSchar) withString:("\t"))
      set strFirstChar to (ocidTabLineString's substringToIndex:(1)) as text
      set numCharLengh to ocidTabLineString's |length| as integer
      set strLastChar to (ocidTabLineString's substringFromIndex:(numCharLengh - 1)) as text
      if strFirstChar is "\"" then
        set ocidRange to refMe's NSMakeRange(0, 1)
(ocidTabLineString's deleteCharactersInRange:(ocidRange))
      end if
      if strLastChar is "\"" then
        set numCharLengh to ocidTabLineString's |length| as integer
        set ocidRange to refMe's NSMakeRange((numCharLengh - 1), 1)
(ocidTabLineString's deleteCharactersInRange:(ocidRange))
      end if
      #出力用のテキストにセット
(ocidOutPutString's appendString:(ocidTabLineString))
      #改行を付与
(ocidOutPutString's appendString:(strNewlineCharacter))
    end repeat
    #保存
    set listDone to (ocidOutPutString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
    
  end repeat
  
end open

|

«[NSPredicate]fluentuiのアイコン検索フォルダ名で検索(簡易検索)