postalcode

郵便番号検索v3(ダウンロードURLが変わったのに対応・複数の検索語句の処理に挑戦してみた)



ダウンロード - postcodedbv3.zip



検索用のDBを作成
AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004#検索用のDBを作成します
005#1回実行したら変更あるまで実行しなくてOK
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012property refMe : a reference to current application
013set appFileManager to refMe's NSFileManager's defaultManager()
014##########################
015#設定項目 
016#ZIPファイルのURL
017set strURL to ("https://www.post.japanpost.jp/zipcode/dl/utf/zip/utf_ken_all.zip") as text
018
019##########################
020#パス関連
021set ocidURLString to refMe's NSString's stringWithString:(strURL)
022set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
023set strURL to ocidURL's absoluteString() as text
024set ocidFileName to ocidURL's lastPathComponent()
025#保存先
026set aliasPathToMe to (path to me) as alias
027set strPathToMe to (POSIX path of aliasPathToMe) as text
028set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
029set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath()
030set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false)
031set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
032#保存先
033set ocidSaveDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data") isDirectory:(true)
034#古いデータはゴミ箱へ
035set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidSaveDirPathURL) |error| :(reference))
036#その上でフォルダを作っておく
037set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
038ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
039set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
040#
041set ocidDBFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("postno.db") isDirectory:(false)
042#
043set ocidZipFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)
044#コマンド用のパス
045set strSaveDirPath to ocidSaveDirPathURL's |path|() as text
046set strZipFilePath to ocidZipFilePathURL's |path|() as text
047set strDBFilePath to ocidDBFilePathURL's |path|() as text
048##########################
049#ダウンロード
050set ocidOption to (refMe's NSDataReadingMappedIfSafe)
051set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference)
052if (item 2 of listResponse) = (missing value) then
053  log "正常処理"
054  set ocidReadData to (item 1 of listResponse)
055else if (item 2 of listResponse) (missing value) then
056  set strErrorNO to (item 2 of listResponse)'s code() as text
057  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
058  refMe's NSLog("■:" & strErrorNO & strErrorMes)
059  return "エラーしました" & strErrorNO & strErrorMes
060end if
061##NSDataで保存
062set ocidOption to (refMe's NSDataWritingAtomic)
063set listDone to ocidReadData's writeToURL:(ocidZipFilePathURL) options:(ocidOption) |error| :(reference)
064if (item 1 of listDone) is true then
065  log "writeToURL 正常処理"
066else if (item 2 of listDone) (missing value) then
067  set strErrorNO to (item 2 of listDone)'s code() as text
068  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
069  refMe's NSLog("■:" & strErrorNO & strErrorMes)
070  return "writeToURL エラーしました" & strErrorNO & strErrorMes
071end if
072##########################
073#解凍
074set strCommandText to ("/usr/bin/bsdtar -xzvf \"" & strZipFilePath & "\"  -C \"" & strSaveDirPath & "\"")
075set strResponse to doZshShellScript(strCommandText)
076if strResponse is false then
077  return "解凍に失敗しまし"
078else
079  set listDone to (appFileManager's trashItemAtURL:(ocidZipFilePathURL) resultingItemURL:(ocidZipFilePathURL) |error| :(reference))
080end if
081##########################
082#解凍後のファイル
083set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
084set ocidKeyArray to refMe's NSMutableArray's alloc()'s init()
085ocidKeyArray's addObject:(refMe's NSURLPathKey)
086set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidSaveDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
087#解凍したCSVファイル
088set ocidCSVFilePathURL to (item 1 of listResponse)'s firstObject()
089#DBにインポートするファイル
090set ocidImportFilePathURL to ocidCSVFilePathURL's URLByAppendingPathExtension:("import.csv")
091set strImportFilePath to ocidImportFilePathURL's |path|() as text
092##########################
093#下準備
094set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidCSVFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
095set ocidReadString to (item 1 of listResponse)
096#クオテーションを置換削除
097set ocidReadString to (ocidReadString's stringByReplacingOccurrencesOfString:("\"") withString:(""))
098#保存 ファイルサイズが大きいので別名保存
099set listDone to ocidReadString's writeToURL:(ocidImportFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
100if (item 1 of listDone) is true then
101  log "writeToURL 正常終了"
102else if (item 1 of listDone) is false then
103  log (item 2 of listDone)'s localizedDescription() as text
104  return "writeToURL 保存に失敗しました"
105end if
106##########################
107#【1】インポート
108log "データインポート開始"
109set strCommandText to ("/usr/bin/sqlite3 \"" & strDBFilePath & "\" <<EOF\nCREATE TABLE postalcode (code TEXT,old_no TEXT,p_no TEXT,prefecture_kana TEXT,city_kana TEXT,town_kana TEXT,prefecture TEXT,city TEXT,town TEXT,more INTEGER,azamore INTEGER,chomore INTEGER,containmore INTEGER,updatemore INTEGER,changemore INTEGER);\n.mode csv\n.import \"" & strImportFilePath & "\" postalcode\nEOF")
110set strResponse to doZshShellScript(strCommandText)
111if strResponse is false then
112  return "インポートに失敗しました"
113else
114  log "データインポート終了"
115end if
116
117##########################
118#【2】インポート
119log "都道府県+地区町村作成開始"
120set strCommandText to ("/usr/bin/sqlite3 \"" & strDBFilePath & "\" <<EOF\nALTER TABLE postalcode ADD COLUMN pref_and_city TEXT;\nEOF")
121set strResponse to doZshShellScript(strCommandText)
122if strResponse is false then
123  return "インポートに失敗しました"
124else
125  log "都道府県+地区町村作成開始 OK"
126end if
127
128##########################
129#【3】インポート
130log "都道府県+地区町村 データ結合開始"
131set strCommandText to ("/usr/bin/sqlite3 \"" & strDBFilePath & "\" <<EOF\nUPDATE postalcode SET pref_and_city = prefecture || city;\nEOF")
132set strResponse to doZshShellScript(strCommandText)
133if strResponse is false then
134  return "インポートに失敗しました"
135else
136  log "都道府県+地区町村 データ結合 OK"
137end if
138
139##########################
140#【4】インポート
141log "地区町村+町名作成開始"
142set strCommandText to ("/usr/bin/sqlite3 \"" & strDBFilePath & "\" <<EOF\nALTER TABLE postalcode ADD COLUMN city_and_town TEXT;\nEOF")
143set strResponse to doZshShellScript(strCommandText)
144if strResponse is false then
145  return "インポートに失敗しました"
146else
147  log "地区町村+町名作成開始 OK"
148end if
149
150##########################
151#【5】インポート
152log "地区町村+町名作成開始  データ結合開始"
153set strCommandText to ("/usr/bin/sqlite3 \"" & strDBFilePath & "\" <<EOF\nUPDATE postalcode SET city_and_town = city || town;\nEOF")
154set strResponse to doZshShellScript(strCommandText)
155if strResponse is false then
156  return "インポートに失敗しました"
157else
158  log "地区町村+町名作成開始  データ結合開始 ok"
159end if
160
161##########################
162#後処理
163set listDone to (appFileManager's trashItemAtURL:(ocidImportFilePathURL) resultingItemURL:(ocidImportFilePathURL) |error| :(reference))
164set listDone to (appFileManager's trashItemAtURL:(ocidCSVFilePathURL) resultingItemURL:(ocidCSVFilePathURL) |error| :(reference))
165
166return "終了"
167##########################
168# 【M】Bash 実行
169to doBashShellScript(argCommandText)
170  set strCommandText to argCommandText as text
171  log "\r" & strCommandText & "\r"
172  set strExec to ("/bin/bash -c '" & strCommandText & "'") as text
173  ##########
174  #コマンド実行
175  try
176    log "コマンド開始"
177    set strResnponse to (do shell script strExec) as text
178    log "コマンド終了"
179  on error
180    return false
181  end try
182  return strResnponse
183end doBashShellScript
184
185##########################
186# 【N】ZSH 実行
187to doZshShellScript(argCommandText)
188  set strCommandText to argCommandText as text
189  log "\r" & strCommandText & "\r"
190  set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
191  ##########
192  #コマンド実行
193  try
194    log "コマンド開始"
195    set strResnponse to (do shell script strExec) as text
196    log "コマンド終了"
197  on error
198    return false
199  end try
200  return strResnponse
201end doZshShellScript
202return
AppleScriptで生成しました

検索用
AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# V2 都道府県市区町村を追加
005# V3ダウンロードURLとファイル名が変更されたのに対応
006# com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008##自分環境がos12なので2.8にしているだけです
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
016
017#############################
018### クリップボードの中身取り出し
019###初期化
020set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
021set ocidPastBoardTypeArray to ocidPasteboard's types
022###テキストがあれば
023set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
024if boolContain = true then
025  ###値を格納する
026  tell application "Finder"
027    set strReadString to (the clipboard as text) as text
028  end tell
029  ###Finderでエラーしたら
030else
031  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
032  if boolContain = true then
033    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
034    set strReadString to ocidReadString as text
035  else
036    log "テキストなし"
037    set strReadString to "" as text
038  end if
039end if
040
041#############################
042###DBファイルへのパス
043tell application "Finder"
044  set aliasPathToMe to (path to me) as alias
045  set aliasContainerDirPath to (container of aliasPathToMe) as alias
046end tell
047set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
048set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
049set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
050set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
051set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/postno.db")
052set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text
053
054set strMes to ("住所で検索 一部分でも可\r神奈川とかで指定すると検索結果が多くなります\n郵便番号で検索の場合は数字のみ(ハイフン除いてください)") as text
055set strQueryText to strReadString as text
056
057##############################
058###ダイアログ
059set strName to (name of current application) as text
060if strName is "osascript" then
061  tell application "Finder" to activate
062else
063  tell current application to activate
064end if
065set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
066try
067  set recordResult to (display dialog strMes with title "郵便番号検索" default answer strQueryText buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
068  if "OK" is equal to (button returned of recordResult) then
069    set strReturnedText to (text returned of recordResult) as text
070  else if (gave up of recordResult) is true then
071    return "時間切れです"
072  else
073    return "キャンセル"
074  end if
075on error
076  log "エラーしました"
077  return
078end try
079##############################
080###戻り値整形
081set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
082###タブと改行を除去しておく
083set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
084ocidTextM's appendString:(ocidResponseText)
085##改行除去
086set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
087set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
088##タブ除去
089set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
090set strSearchText to ocidTextM as text
091##############################
092###ひらがなのみの場合はカタカナに
093set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error| :(reference)
094set ocidRegex to (item 1 of listRegex)
095set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
096log ocidTextRange
097set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
098if (numMach as integer) = 1 then
099  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
100  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
101end if
102###数字がなければ全角に
103set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
104set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
105##############################
106#この時点でスペースは全角だから
107set ocidKeyWordArray to ocidTextM's componentsSeparatedByString:(" ")
108#判定用
109set appPredicateNum to refMe's NSPredicate's predicateWithFormat_("SELF MATCHES %@", "^[0-9]+$")
110set appPredicateKana to refMe's NSPredicate's predicateWithFormat_("SELF MATCHES %@", "^[\\u30A0-\\u30FF]+$")
111#県名リスト
112set listPrefecture to {"北海道", "青森", "岩手", "宮城", "秋田", "山形", "福島", "茨城", "栃木", "群馬", "埼玉", "千葉", "東京", "神奈川", "新潟", "富山", "石川", "福井", "山梨", "長野", "岐阜", "静岡", "愛知", "三重", "滋賀", "京都", "大阪", "兵庫", "奈良", "和歌山", "鳥取", "島根", "岡山", "広島", "山口", "徳島", "香川", "愛媛", "高知", "福岡", "佐賀", "長崎", "熊本", "大分", "宮崎", "鹿児島", "沖縄"} as list
113#県名リスト
114set listPrefectureFull to {"北海道", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県", "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県", "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県", "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県"} as list
115#県名リスト
116set listPrefectureKANA to {"ホッカイドウ", "アオモリ", "イワテ", "ミヤギ", "アキタ", "ヤマガタ", "フクシマ", "イバラキ", "トチギ", "グンマ", "サイタマ", "チバ", "トウキョウ", "カナガワ", "ニイガタ", "トヤマ", "イシカワ", "フクイ", "ヤマナシ", "ナガノ", "ギフ", "シズオカ", "アイチ", "ミエ", "シガ", "キョウト", "オオサカ", "ヒョウゴ", "ナラ", "ワカヤマ", "トットリ", "シマネ", "オカヤマ", "ヒロシマ", "ヤマグチ", "トクシマ", "カガワ", "エヒメ", "コウチ", "フクオカ", "サガ", "ナガサキ", "クマモト", "オオイタ", "ミヤザキ", "カゴシマ", "オキナワ"} as list
117#県名リスト
118set listPrefectureKANAFull to {"ホッカイドウ", "アオモリケン", "イワテケン", "ミヤギケン", "アキタケン", "ヤマガタケン", "フクシマケン", "イバラキケン", "トチギケン", "グンマケン", "サイタマケン", "チバケン", "トウキョウト", "カナガワケン", "ニイガタケン", "トヤマケン", "イシカワケン", "フクイケン", "ヤマナシケン", "ナガノケン", "ギフケン", "シズオカケン", "アイチケン", "ミエケン", "シガケン", "キョウトフ", "オオサカフ", "ヒョウゴケン", "ナラケン", "ワカヤマケン", "トットリケン", "シマネケン", "オカヤマケン", "ヒロシマケン", "ヤマグチケン", "トクシマケン", "カガワケン", "エヒメケン", "コウチケン", "フクオカケン", "サガケン", "ナガサキケン", "クマモトケン", "オオイタケン", "ミヤザキケン", "カゴシマケン", "オキナワケン"} as list
119####################
120#クエリー文を生成
121set boolContainPno to false as boolean
122set boolContainPrefecture to false as boolean
123#次工程に回す
124set listSearchCom to {} as list
125repeat with itemKeyWord in ocidKeyWordArray
126  #数字のみ判定
127  set boolNUM to (appPredicateNum's evaluateWithObject:(itemKeyWord)) as boolean
128  #カタカナのみ判定
129  set boolKANA to (appPredicateKana's evaluateWithObject:(itemKeyWord)) as boolean
130  #数字なら
131  if boolNUM is true then
132    #郵便番号検索
133    set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
134    set strItemKeyWord to (itemKeyWord's stringByApplyingTransform:(ocidTransform) |reverse|:false) as text
135    set strAddCom to ("p_no LIKE '%" & strItemKeyWord & "%'") as text
136    copy strAddCom to end of listSearchCom
137    set boolContainPno to true as boolean
138  else if boolKANA is true then
139    #カナなら
140    set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
141    set strItemKeyWord to (itemKeyWord's stringByApplyingTransform:(ocidTransform) |reverse|:true) as text
142    if listPrefectureKANA contains strItemKeyWord then
143      #県名リストに含まれる検索語句の場合
144      set strAddCom to ("prefecture_kana LIKE '%" & strItemKeyWord & "%'") as text
145      copy strAddCom to end of listSearchCom
146      set boolContainPrefecture to true as boolean
147    else if listPrefectureKANAFull contains strItemKeyWord then
148      #県名リストに含まれる検索語句の場合
149      set strAddCom to ("prefecture_kana IS '" & strItemKeyWord & "'") as text
150      copy strAddCom to end of listSearchCom
151      set boolContainPrefecture to true as boolean
152    else
153      set strAddCom to ("city_kana LIKE  '%" & strItemKeyWord & "%'") as text
154      copy strAddCom to end of listSearchCom
155      set strAddCom to ("town_kana LIKE  '%" & strItemKeyWord & "%'") as text
156      copy strAddCom to end of listSearchCom
157    end if
158  else
159    #数字 カナ 以外なら
160    set strItemKeyWord to itemKeyWord as text
161    #県名リストに含まれる検索語句の場合
162    if listPrefecture contains strItemKeyWord then
163      set strAddCom to ("prefecture LIKE '%" & strItemKeyWord & "%'") as text
164      copy strAddCom to beginning of listSearchCom
165      #set strAddCom to ("city_and_town LIKE  '%" & strItemKeyWord & "%'") as text
166      # copy strAddCom to end of listSearchCom
167      set boolContainPrefecture to true as boolean
168    else if listPrefectureFull contains strItemKeyWord then
169      #県名リストに含まれる検索語句の場合
170      set strAddCom to ("prefecture IS '" & strItemKeyWord & "'") as text
171      copy strAddCom to beginning of listSearchCom
172      set strAddCom to ("city_and_town LIKE  '%" & strItemKeyWord & "%'") as text
173      copy strAddCom to end of listSearchCom
174      set boolContainPrefecture to true as boolean
175    else
176      set strAddCom to ("city_and_town LIKE  '%" & strItemKeyWord & "%'") as text
177      copy strAddCom to end of listSearchCom
178      #set strAddCom to ("town LIKE  '%" & strItemKeyWord & "%'") as text
179      #copy strAddCom to end of listSearchCom
180    end if
181  end if
182end repeat
183
184##############################
185##クエリーを生成
186#メインのクエリー
187set strQuery to ("") as text
188#AND検索用のサブクエリー
189set strSubQuery to ("") as text
190#検索語句数
191set numCntList to (count of listSearchCom) as integer
192#検索語句の数だけ繰り返し
193repeat with itemNo from 1 to numCntList by 1
194  #検索語句
195  set strItemCom to (item itemNo of listSearchCom) as text
196  #検索語句が1つだけなら
197  if numCntList = 1 then
198    set strSubQuery to ("" & strQuery & strItemCom & "") as text
199    exit repeat
200  end if
201  ##検索語句が複数ある場合
202  #郵便番号をメインのクエリーに
203  if strItemCom contains "p_no" then
204    set strPnoQuery to strItemCom as text
205  end if
206  #県名をメインのクエリーに
207  if strItemCom contains "prefecture" then
208    set strPrefectureQuery to strItemCom as text
209  end if
210  ##検索語句が最初なら
211  if itemNo = 1 then
212    if strItemCom contains "p_no" then
213      #郵便番号はAND
214      set strSubQuery to (strItemCom & " AND " & "") as text
215    else if strItemCom contains "prefecture" then
216      #県名はAND
217      set strSubQuery to (strItemCom & " AND " & "") as text
218    else
219      #それ以外の場合
220      #次の検索語句を調べて
221      set strItemNextCom to (item (itemNo + 1) of listSearchCom) as text
222      #次が郵便番号はAND
223      if strItemNextCom contains "p_no" then
224        set strSubQuery to ("" & strItemCom & " AND " & "") as text
225      else if strItemNextCom contains "prefecture" then
226        #次が県名はAND
227        set strSubQuery to ("" & strItemCom & " AND " & "") as text
228      else
229        #それ以外の場合はOR
230        set strSubQuery to (strItemCom & " OR " & "") as text
231      end if
232    end if
233  else if itemNo = numCntList then
234    set strSubQuery to ("" & strSubQuery & strItemCom & "") as text
235  else
236    if strItemCom contains "p_no" then
237      #郵便番号はAND
238      set strSubQuery to ("" & strSubQuery & strItemCom & " AND " & "") as text
239    else if strItemCom contains "prefecture" then
240      #県名はAND
241      set strSubQuery to ("" & strSubQuery & strItemCom & " AND " & "") as text
242    else
243      set strItemNextCom to (item (itemNo + 1) of listSearchCom) as text
244      if strItemNextCom contains "p_no" then
245        #郵便番号はAND
246        set strSubQuery to ("" & strSubQuery & strItemCom & " AND " & "") as text
247      else if strItemNextCom contains "prefecture" then
248        #県名はAND
249        set strSubQuery to ("" & strSubQuery & strItemCom & " AND " & "") as text
250      else
251        #それ以外の場合はOR
252        set strSubQuery to ("" & strSubQuery & strItemCom & " OR " & "") as text
253      end if
254      
255    end if
256  end if
257  
258end repeat
259#メインのクエリーにサブクエリーをANDでセット
260#郵便番号を優先する
261if boolContainPrefecture is true then
262  set strQuery to ("" & strPrefectureQuery & " AND (" & strSubQuery & ")") as text
263else if boolContainPno is true then
264  set strQuery to ("" & strPnoQuery & " AND (" & strSubQuery & ")") as text
265else
266  #メインのクエリーが無い場合はそのままセット
267  set strQuery to strSubQuery
268end if
269#コマンド整形
270set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*)  FROM postalcode WHERE " & strQuery & ";\"") as text
271log "\r" & strCommandText & "\r"
272###検索結果の件数
273set numQueryCnt to (do shell script strCommandText) as integer
274
275
276##############################
277###件数が100超える場合は中止を促す
278if numQueryCnt > 100 then
279  log "検索結果100件超です"
280  ###ダイアログを前面に出す
281  set strName to (name of current application) as text
282  if strName is "osascript" then
283    tell application "Finder" to activate
284  else
285    tell current application to activate
286  end if
287  ##1件の処理時間
288  set numMin to (0.01 * numQueryCnt) as integer
289  set strAlertMes to "検索結果100件超です(" & numQueryCnt & "件)\r継続すると結果表示まで約:" & numMin & "秒かかります" as text
290  try
291    set recordResponse to (display alert ("【選んでください】\r" & strAlertMes) buttons {"継続", "終了"} default button "継続" cancel button "終了" as informational giving up after 10) as record
292  on error
293    log "エラーしました"
294    return "キャンセルしました。処理を中止します。再度実行してください"
295  end try
296  if true is equal to (gave up of recordResponse) then
297    return "時間切れです。処理を中止します。再度実行してください"
298  end if
299else if numQueryCnt = 0 then
300  log "検索結果0件です"
301end if
302####処理継続の場合はそのまま進む
303
304set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE " & strQuery & ";\"") as text
305log strCommandText
306
307set strResponse to (do shell script strCommandText) as text
308
309
310########################################
311##コマンドの戻り値を改行でリストに
312set AppleScript's text item delimiters to "\r"
313set listResponse to every text item of strResponse
314set AppleScript's text item delimiters to ""
315
316########################################
317##HTML 基本構造
318###スタイル
319set strStylle to "<style>table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody th { overflow-x: hidden;} tbody td { word-wrap: break-all;overflow-wrap: anywhere;text-overflow: ellipsis;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }</style>"
320###ヘッダー部
321set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
322###ボディ
323set strBody to ""
324###最後
325set strHtmlEndBody to "</body></html>"
326###HTML書き出し用のテキスト初期化
327set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
328####
329(ocidHTMLString's appendString:strHead)
330#########
331###テーブルの開始部
332set strHTML to ("<table><caption title=\"タイトル\">検索結果:" & strReturnedText & "<br>検索結果数: " & numQueryCnt & "</caption>") as text
333set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 郵便番号 </th><th title=\"項目3\" scope=\"col\"> 住所 </th><th title=\"項目4\"  scope=\"col\"> 読み </th><th title=\"項目5\"  scope=\"col\">団体コード</th><th title=\"項目6\"  scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
334(ocidHTMLString's appendString:(strHTML))
335set numLineNo to 1 as integer
336repeat with itemLine in listResponse
337  ###各行タブ区切りなのでタブでリストにする
338  set AppleScript's text item delimiters to "\t"
339  set listLineText to every text item of itemLine
340  set AppleScript's text item delimiters to ""
341  ###必要な項目を取得
342  set strCityCode to (item 1 of listLineText) as text
343  set strPostNo to (item 3 of listLineText) as text
344  set strAddText to ((item 7 of listLineText) & (item 8 of listLineText) & (item 9 of listLineText)) as text
345  set strKana to ((item 4 of listLineText) & (item 5 of listLineText) & (item 6 of listLineText)) as text
346  ###リンク生成
347  set strLinkURL to ("https://www.post.japanpost.jp/cgi-zip/zipcode.php?zip=" & strPostNo & "")
348  set strMapURL to ("https://www.google.com/maps/search/郵便番号+" & strPostNo & "")
349  set strMapAppURL to ("http://maps.apple.com/?q=郵便番号+" & strPostNo & "")
350  set strLINK to "<a href=\"" & strLinkURL & "\" target=\"_blank\">郵政</a>&nbsp;|&nbsp;<a href=\"" & strMapURL & "\" target=\"_blank\">Google</a>&nbsp;|&nbsp;<a href=\"" & strMapAppURL & "\" target=\"_blank\">Map</a>"
351  ###HTMLにして
352  set strHTML to ("<tr><th title=\"項番1\"  scope=\"row\">" & numLineNo & "</th><td title=\"項目2\" style=\"white-space: nowrap;\">" & strPostNo & "</td><td title=\"項目3\">" & strAddText & "</td><td title=\"項目4\"><small>" & strKana & "</small></td><td title=\"項目5\">" & strCityCode & "</td><td title=\"項目6\">" & strLINK & "</td></tr>") as text
353  (ocidHTMLString's appendString:(strHTML))
354  set numLineNo to numLineNo + 1 as integer
355end repeat
356
357set strHTML to ("</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\"  scope=\"row\">post.japanpost.jp</th></tr></tfoot></table>") as text
358####テーブルまでを追加
359(ocidHTMLString's appendString:(strHTML))
360####終了部を追加
361(ocidHTMLString's appendString:(strHtmlEndBody))
362
363###ディレクトリ
364set appFileManager to refMe's NSFileManager's defaultManager()
365set ocidTempDirURL to appFileManager's temporaryDirectory()
366set ocidUUID to refMe's NSUUID's alloc()'s init()
367set ocidUUIDString to ocidUUID's UUIDString
368set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
369set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
370# 777-->511 755-->493 700-->448 766-->502
371ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
372set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
373###パス
374
375set strFileName to (strSearchText & ".html") as text
376set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
377###ファイルに書き出し
378set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
379####テキストエディタで開く
380set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
381(*
382tell application "TextEdit"
383  activate
384  open file aliasFilePath
385end tell
386*)
387tell application "Safari"
388  activate
389  open file aliasFilePath
390end tell
391
392
393
394
AppleScriptで生成しました

|

郵便番号検索 v2

都道府県+市区町村名に対応

ダウンロード - 郵便番号検索v2.zip


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

#!/bin/bash
# V2 都道府県市区町村を追加
#com.cocolog-nifty.quicktimer.icefloe
##################################################
###設定項目 CSVのファイル名
STR_CSV_FILE_NAME="utf_all.csv"
### path to me
SCRIPT_PATH="${BASH_SOURCE[0]}"
/bin/echo "このスクリプトのパス $SCRIPT_PATH"
STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
/bin/echo "コンテナディレクトリ $STR_CONTAINER_DIR_PATH"
STR_DATA_DIR_PATH="$STR_CONTAINER_DIR_PATH/data"
/bin/mkdir -p "$STR_DATA_DIR_PATH"
/bin/echo "データ格納ディレクトリ $STR_DATA_DIR_PATH"
STR_CSV_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME"
/bin/echo "CSVのファイルパス $STR_CSV_FILE_PATH"
STR_IMPORT_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME.import.csv"
/bin/echo "SQLインポート用CSVの書き出しパス $STR_IMPORT_FILE_PATH"
STR_DB_FILE_PATH="$STR_DATA_DIR_PATH/postno.db"
/bin/echo "SQLDBのパス $STR_DB_FILE_PATH"
##################################################
###古いデータは削除する
/usr/bin/touch "$STR_IMPORT_FILE_PATH"
/usr/bin/touch "$STR_DB_FILE_PATH"
/usr/bin/touch "$STR_CSV_FILE_PATH"
/bin/rm  "$STR_IMPORT_FILE_PATH"
/bin/rm  "$STR_DB_FILE_PATH"
/bin/rm  "$STR_CSV_FILE_PATH"
##################################################
STR_URL="https://www.post.japanpost.jp/zipcode/dl/utf/zip/utf_all.zip"
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ $USER_TEMP_DIR"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --connect-timeout 20; then
  /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --http1.1 --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
fi
/bin/echo "ダウンロードしたZIPファイル $USER_TEMP_DIR/utf_all.zip"
##################################################
###解凍
/usr/bin/cd "$STR_DATA_DIR_PATH"
/usr/bin/bsdtar -xzvf "$USER_TEMP_DIR/utf_all.zip" -C "$STR_DATA_DIR_PATH"
/bin/echo "ダウンロードデータ解凍OK"
##################################################
###クオテーション除去
STR_TMP_FILE_PATH="$USER_TEMP_DIR/$STR_CSV_FILE_NAME.tmp.csv"
/usr/bin/sed 's/"//g' "$STR_CSV_FILE_PATH" > "$STR_TMP_FILE_PATH"
###改行変更
/usr/bin/sed 's/\r$//' "$STR_TMP_FILE_PATH" > "$STR_IMPORT_FILE_PATH"
/bin/echo "データ整形終了"
##################################################
###1行目挿入 この処理は不要だった
## STR_HEADER_TEXT="code,old_no,p_no,prefecture_kana,city_kana,town_kana,prefecture,city,town,more,aza,cho,contain,update,change"
## /usr/bin/touch "$STR_IMPORT_FILE_PATH"
## /bin/echo "$STR_HEADER_TEXT" > "$STR_IMPORT_FILE_PATH"
## /bin/cat "$STR_TMPB_FILE_PATH" >> "$STR_IMPORT_FILE_PATH"
##################################################
/bin/echo "データインポート開始"
###インポート DB作成
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
CREATE TABLE postalcode (code TEXT,old_no TEXT,p_no TEXT,prefecture_kana TEXT,city_kana TEXT,town_kana TEXT,prefecture TEXT,city TEXT,town TEXT,more INTEGER,azamore INTEGER,chomore INTEGER,containmore INTEGER,updatemore INTEGER,changemore INTEGER);
.mode csv
.import "$STR_IMPORT_FILE_PATH" postalcode
EOF
/bin/echo "データインポート終了"
sleep 2
/bin/echo "都道府県+地区町村作成開始"
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
ALTER TABLE postalcode ADD COLUMN pref_and_city TEXT;
EOF
/bin/echo "都道府県+地区町村作成開始 OK"

/bin/echo "都道府県+地区町村 データ結合開始"
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
UPDATE postalcode SET pref_and_city = prefecture || city;
EOF
/bin/echo "都道府県+地区町村 データ結合開始 ok"


/bin/echo "処理終了しました"
exit 0



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# V2 都道府県市区町村を追加
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
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



#############################
### クリップボードの中身取り出し
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "" as text
  end if
end if



#############################
###DBファイルへのパス
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/postno.db")
set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text

set strMes to ("住所で検索 一部分でも可\r神奈川とかで指定すると検索結果が多くなります") as text
set strQueryText to strReadString as text

##############################
###ダイアログ
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 aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "郵便番号検索" default answer strQueryText buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
  if "OK" is equal to (button returned of recordResult) then
    set strReturnedText to (text returned of recordResult) as text
  else if (gave up of recordResult) is true then
return "時間切れです"
  else
return "キャンセル"
  end if
on error
  log "エラーしました"
return
end try
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##############################
###ひらがなのみの場合はカタカナに
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
log ocidTextRange
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
if (numMach as integer) = 1 then
  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
end if
###数字がなければ全角に
set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
##############################
##カタカナと漢字混在で検索方法が異なる
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ァ-ヶー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
set numMach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
set strSearchText to ocidTextM as text
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT COUNT(*) FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
###検索結果の件数
set numQueryCnt to (do shell script strCommandText) as integer
##############################
###件数が100超える場合は中止を促す
if numQueryCnt > 100 then
  log "検索結果100件超です"
  ###ダイアログを前面に出す
  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
  ##1件の処理時間
  set numMin to (0.01 * numQueryCnt) as integer
  set strAlertMes to "検索結果100件超です(" & numQueryCnt & "件)\r継続すると結果表示まで約:" & numMin & "秒かかります" as text
  try
    set recordResponse to (display alert ("【選んでください】\r" & strAlertMes) buttons {"継続", "終了"} default button "継続" cancel button "終了" as informational giving up after 10) as record
  on error
    log "エラーしました"
return "キャンセルしました。処理を中止します。再度実行してください"
  end try
  if true is equal to (gave up of recordResponse) then
return "時間切れです。処理を中止します。再度実行してください"
  end if
else if numQueryCnt = 0 then
  log "検索結果0件です"
end if
####処理継続の場合はそのまま進む
if (numMach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%' OR pref_and_city LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
set strResponse to (do shell script strCommandText) as text


########################################
##コマンドの戻り値を改行でリストに
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""

########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
#########
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption title=\"タイトル\">検索結果:" & strReturnedText & "</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 郵便番号 </th><th title=\"項目3\" scope=\"col\"> 住所 </th><th title=\"項目4\" scope=\"col\"> 読み </th><th title=\"項目5\" scope=\"col\">団体コード</th><th title=\"項目6\" scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
(ocidHTMLString's appendString:(strHTML))
set numLineNo to 1 as integer
repeat with itemLine in listResponse
  ###各行タブ区切りなのでタブでリストにする
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of itemLine
  set AppleScript's text item delimiters to ""
  ###必要な項目を取得
  set strCityCode to (item 1 of listLineText) as text
  set strPostNo to (item 3 of listLineText) as text
  set strAddText to ((item 7 of listLineText) & (item 8 of listLineText) & (item 9 of listLineText)) as text
  set strKana to ((item 4 of listLineText) & (item 5 of listLineText) & (item 6 of listLineText)) as text
  ###リンク生成
  set strLinkURL to ("https://www.post.japanpost.jp/cgi-zip/zipcode.php?zip=" & strPostNo & "")
  set strMapURL to ("https://www.google.com/maps/search/郵便番号+" & strPostNo & "")
  set strMapAppURL to ("http://maps.apple.com/?q=郵便番号+" & strPostNo & "")
  set strLINK to "<a href=\"" & strLinkURL & "\" target=\"_blank\">郵政</a>&nbsp;|&nbsp;<a href=\"" & strMapURL & "\" target=\"_blank\">Google</a>&nbsp;|&nbsp;<a href=\"" & strMapAppURL & "\" target=\"_blank\">Map</a>"
  ###HTMLにして
  set strHTML to ("<tr><th title=\"項番1\" scope=\"row\">" & numLineNo & "</th><td title=\"項目2\"><b>" & strPostNo & "</b></td><td title=\"項目3\">" & strAddText & "</td><td title=\"項目4\"><small>" & strKana & "</small></td><td title=\"項目5\">" & strCityCode & "</td><td title=\"項目6\">" & strLINK & "</td></tr>") as text
(ocidHTMLString's appendString:(strHTML))
  set numLineNo to numLineNo + 1 as integer
end repeat

set strHTML to ("</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\" scope=\"row\">post.japanpost.jp</th></tr></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス

set strFileName to (strSearchText & ".html") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
(*
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
tell application "Safari"
  activate
  open file aliasFilePath
end tell






|

郵便番号検索

ダウンロード - 郵便番号検索v1.zip


DB検索 結果をHTMLで表示

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# DB検索用
# 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
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807


#############################
###DBファイルへのパス
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDirPath to (container of aliasPathToMe) as alias
end tell
set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
set ocidContainerDirPathStr to refMe's NSString's stringWithString:(strContainerDirPath)
set ocidContainerDirPath to ocidContainerDirPathStr's stringByStandardizingPath()
set ocidContainerDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidContainerDirPath) isDirectory:true)
set ocidDBFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("bin/data/postno.db")
set strDbFilePathURL to (ocidDBFilePathURL's |path|()) as text
#############################
### クリップボードの中身取り出し
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
    log "テキストなし"
    set strReadString to "" as text
  end if
end if
##############################
###ダイアログ
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
set strMes to ("住所で検索 一部分でも可\r神奈川とかで指定すると検索結果が多くなります")
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "郵便番号検索" default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
on error
  log "エラーしました"
return
end try

if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
##############################
###戻り値整形
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
##############################
###ひらがなのみの場合はカタカナに
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ぁ-んー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
log ocidTextRange
set numPach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
if (numPach as integer) = 1 then
  set ocidTransform to (refMe's NSStringTransformHiraganaToKatakana)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:false)
end if
###数字がなければ全角に
set ocidTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:(ocidTransform) |reverse|:true)
########################################
##カタカナと漢字混在で検索方法が異なる
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:("^[ァ-ヶー]+$") options:(0) |error|:(reference)
set ocidRegex to (item 1 of listRegex)
set ocidTextRange to refMe's NSMakeRange(0, (ocidTextM's |length|()))
set numPach to ocidRegex's numberOfMatchesInString:(ocidTextM) options:0 range:(ocidTextRange)
set strSearchText to ocidTextM as text
if (numPach as integer) = 1 then
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture_kana LIKE '%" & strSearchText & "%' OR city_kana LIKE '%" & strSearchText & "%' OR town_kana LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
else
  set strCommandText to ("/usr/bin/sqlite3 \"" & strDbFilePathURL & "\" -tabs \"SELECT * FROM postalcode WHERE prefecture LIKE '%" & strSearchText & "%' OR city LIKE '%" & strSearchText & "%' OR town LIKE '%" & strSearchText & "%';\"") as text
  log strCommandText
end if
set strResponse to (do shell script strCommandText) as text


########################################
##
set AppleScript's text item delimiters to "\r"
set listResponse to every text item of strResponse
set AppleScript's text item delimiters to ""

########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>#bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[検索語句]" & strSearchText & "</title>" & strStylle & "</head><body>"
###ボディ
set strBody to ""
###最後
set strHtmlEndBody to "</body></html>"
###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
(ocidHTMLString's appendString:strHead)
#########
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption title=\"タイトル\">検索結果:" & strReturnedText & "</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"項目1\" scope=\"row\" > 連番 </th><th title=\"項目2\" scope=\"col\"> 郵便番号 </th><th title=\"項目3\" scope=\"col\"> 住所 </th><th title=\"項目4\" scope=\"col\"> 読み </th><th title=\"項目5\" scope=\"col\">団体コード</th><th title=\"項目6\" scope=\"col\">リンク</th></tr></thead><tbody title=\"検索結果一覧\" >") as text
set numLineNo to 1 as integer
repeat with itemLine in listResponse
  set AppleScript's text item delimiters to "\t"
  set listLineText to every text item of itemLine
  set AppleScript's text item delimiters to ""
  
  set strCityCode to (item 1 of listLineText) as text
  set strPostNo to (item 3 of listLineText) as text
  set strAddText to ((item 7 of listLineText) & (item 8 of listLineText) & (item 9 of listLineText)) as text
  set strKana to ((item 4 of listLineText) & (item 5 of listLineText) & (item 6 of listLineText)) as text
  
  set strLinkURL to ("https://www.post.japanpost.jp/cgi-zip/zipcode.php?zip=" & strPostNo & "")
  set strMapURL to ("https://www.google.com/maps/search/郵便番号+" & strPostNo & "")
  set strMapAppURL to ("http://maps.apple.com/?q=郵便番号+" & strPostNo & "")
  set strLINK to "<a href=\"" & strLinkURL & "\" target=\"_blank\">郵政</a>&nbsp;|&nbsp;<a href=\"" & strMapURL & "\" target=\"_blank\">Google</a>&nbsp;|&nbsp;<a href=\"" & strMapAppURL & "\" target=\"_blank\">Map</a>"
  
  set strHTML to (strHTML & "<tr><th title=\"項番1\" scope=\"row\">" & numLineNo & "</th><td title=\"項目2\"><b>" & strPostNo & "</b></td><td title=\"項目3\">" & strAddText & "</td><td title=\"項目4\"><small>" & strKana & "</small></td><td title=\"項目5\">" & strCityCode & "</td><td title=\"項目6\">" & strLINK & "</td></tr>") as text
  
  set numLineNo to numLineNo + 1 as integer
end repeat


set strHTML to (strHTML & "</tbody><tfoot><tr><th colspan=\"6\" title=\"フッター表の終わり\" scope=\"row\">post.japanpost.jp</th></tr></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###パス

set strFileName to (strSearchText & ".html") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
(*
tell application "TextEdit"
activate
open file aliasFilePath
end tell
*)
tell application "Safari"
  activate
  open file aliasFilePath
end tell

DB作成

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
##################################################
###設定項目 CSVのファイル名
STR_CSV_FILE_NAME="utf_all.csv"
### path to me
SCRIPT_PATH="${BASH_SOURCE[0]}"
/bin/echo "このスクリプトのパス $SCRIPT_PATH"
STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
/bin/echo "コンテナディレクトリ $STR_CONTAINER_DIR_PATH"
STR_DATA_DIR_PATH="$STR_CONTAINER_DIR_PATH/data"
/bin/mkdir -p "$STR_DATA_DIR_PATH"
/bin/echo "データ格納ディレクトリ $STR_DATA_DIR_PATH"
STR_CSV_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME"
/bin/echo "CSVのファイルパス $STR_CSV_FILE_PATH"
STR_IMPORT_FILE_PATH="$STR_DATA_DIR_PATH/$STR_CSV_FILE_NAME.import.csv"
/bin/echo "SQLインポート用CSVの書き出しパス $STR_IMPORT_FILE_PATH"
STR_DB_FILE_PATH="$STR_DATA_DIR_PATH/postno.db"
/bin/echo "SQLDBのパス $STR_DB_FILE_PATH"
##################################################
###古いデータは削除する
/usr/bin/touch "$STR_IMPORT_FILE_PATH"
/usr/bin/touch "$STR_DB_FILE_PATH"
/usr/bin/touch "$STR_CSV_FILE_PATH"
/bin/rm  "$STR_IMPORT_FILE_PATH"
/bin/rm  "$STR_DB_FILE_PATH"
/bin/rm  "$STR_CSV_FILE_PATH"
##################################################
STR_URL="https://www.post.japanpost.jp/zipcode/dl/utf/zip/utf_all.zip"
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ $USER_TEMP_DIR"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --connect-timeout 20; then
  /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/utf_all.zip" "$STR_URL" --http1.1 --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました"
    exit 1
  fi
fi
/bin/echo "ダウンロードしたZIPファイル $USER_TEMP_DIR/utf_all.zip"
##################################################
###解凍
/usr/bin/cd "$STR_DATA_DIR_PATH"
/usr/bin/bsdtar -xzvf "$USER_TEMP_DIR/utf_all.zip" -C "$STR_DATA_DIR_PATH"
/bin/echo "ダウンロードデータ解凍OK"
##################################################
###クオテーション除去
STR_TMP_FILE_PATH="$USER_TEMP_DIR/$STR_CSV_FILE_NAME.tmp.csv"
/usr/bin/sed 's/"//g' "$STR_CSV_FILE_PATH" > "$STR_TMP_FILE_PATH"
###改行変更
/usr/bin/sed 's/\r$//' "$STR_TMP_FILE_PATH" > "$STR_IMPORT_FILE_PATH"
/bin/echo "データ整形終了"
##################################################
###1行目挿入 この処理は不要だった
## STR_HEADER_TEXT="code,old_no,p_no,prefecture_kana,city_kana,town_kana,prefecture,city,town,more,aza,cho,contain,update,change"
## /usr/bin/touch "$STR_IMPORT_FILE_PATH"
## /bin/echo "$STR_HEADER_TEXT" > "$STR_IMPORT_FILE_PATH"
## /bin/cat "$STR_TMPB_FILE_PATH" >> "$STR_IMPORT_FILE_PATH"
##################################################
/bin/echo "データインポート開始"
###インポート DB作成
/usr/bin/sqlite3 "$STR_DB_FILE_PATH" <<EOF
CREATE TABLE postalcode (code TEXT,old_no TEXT,p_no TEXT,prefecture_kana TEXT,city_kana TEXT,town_kana TEXT,prefecture TEXT,city TEXT,town TEXT,more INTEGER,azamore INTEGER,chomore INTEGER,containmore INTEGER,updatemore INTEGER,changemore INTEGER);
.mode csv
.import "$STR_IMPORT_FILE_PATH" postalcode
EOF
/bin/echo "データインポート終了"
/bin/echo "処理終了しました"
exit 0


|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings 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 Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom