20260614

【フォルダーカスタマイズ】複数文字入るフォルダ・カスタマイズ

【フォルダーカスタマイズ】複数文字入るフォルダ・カスタマイズ

NOTE記事一覧ですnote.com

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

フォルダカスタマイズ.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(*
005
006ドロップレット用です
007ファイル>書き出す>からアプリケーションで保存してください
008
009macOS26で新しくなった
010アイコン(文字)付き+色付きフォルダを作成します
011
012各処理に1秒の待ち時間をつけているので
013比較的時間がかかります
014
015v4からこのスクリプトだけで
016SF Symbols、絵文字、通常の文字が入力できます
017
018SF Symbols.appでシンボル名は調べることができます
019https://developer.apple.com/sf-symbols/
020または を参照してください
021https://github.com/andrewtavis/sf-symbols-online
022
023実験中
024ダイアログをcurrent applicationで別にしたのは
025新しい試みで、スクリプトメニューからの実行を考慮してみた
026文字の場合(not SF Symbols)は10文字までの制限を入れた
027
028メッセージやログの2ヶ国語対応に初挑戦
029
030制限事項
031すでにタグが設定してあるフォルダを処理する場合
032ラベル無しを選択すると、設定済みのタグを削除してカラーを無しにします
033
034v1 初回作成
035v1.1 20251017 複数文字入力に対応 グリーンの設定間違いを修正
036v2 20251017 メッセージやダイアログを2ヶ国語対応にしてみた
037v3 20251022 タグの名称をcom.apple.LSSharedFileList.ProjectsItemsから取得するように変更
038v3.1 20251022 フォルダをタグに基づいて色合い調整を有効にするようにした
039v3.1.1 20251025 OSバージョン取得のところを少し治した
040v3.2 20251025 UIプロセスが残ってしまうので プロセスのクリーニングを入れた
041v3.2.1 20251026 ProjectsItemsのインデックス指定のないタグに対応した
042v3.2.2 20251026  NSUserDefaultsの設定誤りを修正
043v3.3 20251026 Symbols名のチェックを入れた
044v4 20251026 文字もSF Symbolsも両方対応するようにした
045v4.0.1 20251115 文字数の最大を10文字にした
046v4.0.2 20251115 UIプロセスクリーニングを少し改良
047v4.1 20251115 インデクスとタグを逆順にしたら良くなったので様子見ることにした
048v4.2 20251122 タグ名部分だけマルチリンガル対応にしたテスト版
049v4.3 20251123 タグ名の取得を見直し修正した
050v.4.4 20251123 カントリーコードと国旗の対応をした
051v.4.4.1 20251203 一部ダイアログをマルチリンガル対応した
052v.4.5 20260408 今日の日付合字版を選択リストに入るようにした
053v.4.6 20260614 パスのエスケープを改良
054v.4.6 20260614 スクリプトアプリケーションでもダイアログがマルチリンガル表記になるようにした
055
056
057このスクリプトのライセンス
058CC0 1.0 全世界 (CC0 1.0)
059https://quicktimer.cocolog-nifty.com/icefloe/2011/01/readme.html#licenseJA
060
061こちらの記事を参考にしました
062https://eclecticlight.co/2025/09/18/customising-folders-in-tahoe/
063Mr. Howardに感謝
064
065Creates a new  color folder feature introduced in macOS 26
066
0671-second delay is added between each process,
068 so it may take a little time to complete.
069
070 SF Symbols version: you can enter a Symbol Name  text.
071 Although not fully verified, characters included in one of macOS’s default fonts,
072 SF Pro, should generally work fine.
073
074SF You can check the symbol name on Symbols.app
075https://developer.apple.com/sf-symbols/
076Or please refer to the following
077https://github.com/andrewtavis/sf-symbols-online
078
079During the experiment
080 The dialog is separated using "current application" ―
081 this is an experimental approach for running from the Script Menu.
082In the case of characters (not SF Symbols), it is limited to 10 characters.
083
084 First attempt at bilingual (English/Japanese) messages and logs.
085
086Limitations
087When processing a folder that already has tags assigned,
088Label selecting “None” will remove the existing tags and clear the color setting.
089
090v1      Initial version
091v1.1   20251017  Added support for multi-character input
092v2      20251017  First attempt at bilingual  messages and logs.
093v3 20251022 Change tag names to be retrieved from com.apple.LSSharedFileList.ProjectsItems
094v3.1 20251022 Enabled color adjustment for folders based on tags
095v3.2 20251025 UI process will remain, so I cleaned the process.
096v3.2.1 20251026 ProjectsItems Corresponded to tags without indexing
097v3.2.2 20251026 NSUserDefaults's Fixed the setting error
098v3.3 20251026 checked the name of Symbols
099v4 20251026 Both letters and SF Symbols are supported.
100v4.0.1 20251115 The maximum number of characters is set to 10 characters
101v4.1 20251115 If I put the index and tag in reverse order, it got better, so I decided to wait and see.
102v4.3 20251123 The acquisition of the tag name has been reviewed and corrected
103v.4.4 20251123 Country code and national flag correspondence
104v.4.5 20260408 Today's date synthet version has been included in the selection list
105v.4.6 20260614 Improve the escape of the path
106v.4.6 20260614 Even in script applications, the dialog is multilingual.
107
108License of this script
109CC0 1.0 Universal (Public Domain Dedication).
110https://quicktimer.cocolog-nifty.com/icefloe/2011/01/readme.html#licenseEN
111
112I referred to this article
113https://eclecticlight.co/2025/09/18/customising-folders-in-tahoe/
114Thanks to Mr. Howard
115
116com.cocolog-nifty.quicktimer.icefloe *)
117----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
118use AppleScript version "2.8"
119use framework "Foundation"
120use framework "AppKit"
121use scripting additions
122property refMe : a reference to current application
123############
124#設定項目
125#処理間待ち時間 デフォルト1秒
126#Waiting time between processing Default 1 second
127property numMagicTime : 1.0 as number
128property listAliasFolderPath : {} as list
129
130on run
131   
132   if listAliasFolderPath is {} then
133      #############################
134      #ダイアログ
135      set strAppFilePath to ("/System/Library/ScriptingAdditions/StandardAdditions.osax") as text
136      set ocidAppFilePathStr to refMe's NSString's stringWithString:(strAppFilePath)
137      set ocidAppFilePath to ocidAppFilePathStr's stringByStandardizingPath()
138      set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath) isDirectory:(true)
139      set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppFilePathURL)
140      set strChooseAFolder to (appBundle's localizedStringForKey:("Choose a Folder") value:("Choose a Folder") table:("Localizable")) as text
141      #
142      set strAppFilePath to "/System/Library/CoreServices/Finder.app" as text
143      set ocidAppFilePathStr to refMe's NSString's stringWithString:(strAppFilePath)
144      set ocidAppFilePath to ocidAppFilePathStr's stringByStandardizingPath()
145      set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath) isDirectory:(true)
146      set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppFilePathURL)
147      set strFolder to (appBundle's localizedStringForKey:("NE89") value:("Folder") table:("LocalizableMerged")) as text
148      set strCustomizeFolder to (appBundle's localizedStringForKey:("N160.2") value:("Customize Folder…") table:("LocalizableMerged")) as text
149      #
150      set strAppFilePath to "/System/Library/Frameworks/AppKit.framework" as text
151      set ocidAppFilePathStr to refMe's NSString's stringWithString:(strAppFilePath)
152      set ocidAppFilePath to ocidAppFilePathStr's stringByStandardizingPath()
153      set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath) isDirectory:(true)
154      set appBundle to refMe's NSBundle's bundleWithURL:(ocidAppFilePathURL)
155      set strMultiple to (appBundle's localizedStringForKey:("Multiple Selection") value:("Multiple Selection") table:("Placeholders")) as text
156      #
157      set strMsg to ("" & strCustomizeFolder & return & strChooseAFolder & return & strMultiple & "") as text
158      set strPrompt to ("" & strCustomizeFolder & return & strChooseAFolder & return & strMultiple & "") as text
159      ############
160      set appFileManager to refMe's NSFileManager's defaultManager()
161      set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
162      set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
163      set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
164      ############
165      tell application "Finder"
166         tell application "SystemUIServer"
167            activate
168            set listAliasFolderPath to (choose folder strMsg with prompt strPrompt default location aliasDefaultLocation with multiple selections allowed without invisibles and showing package contents) as list
169         end tell
170      end tell
171   end if
172   
173   
174   set boolDone to (open listAliasFolderPath) as boolean
175   try
176      with timeout of 3 seconds
177         tell application "System Events" to quit
178      end timeout
179   on error strErrMes number numErrNo
180      log "Interrupt and end" & strErrMes & numErrNo
181      return false
182   end try
183   return boolDone
184end run
185
186
187on open listAliasFolderPath
188   ######################
189   set ocidFolderURLArray to refMe's NSMutableArray's alloc()'s init()
190   #フォルダだけを次工程に回す
191   set appFileManager to refMe's NSFileManager's defaultManager()
192   repeat with itemAliasFolderPath in listAliasFolderPath
193      set aliasFolderPath to itemAliasFolderPath as alias
194      set strDirPath to (POSIX path of aliasFolderPath) as text
195      set ocidDirPathStr to (refMe's NSString's stringWithString:(strDirPath))
196      set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
197      set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) isDirectory:(true))
198      #
199      set listResponse to (ocidDirPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
200      set boolIsDir to (item 2 of listResponse) as boolean
201      if boolIsDir is true then
202         (ocidFolderURLArray's addObject:(ocidDirPathURL))
203      end if
204   end repeat
205   
206   ######################
207   #【設定項目】 Setting items
208   #SF Symbolsのプリセットリスト よく使うものを登録して利用します
209   #Preset list of SF Symbols Register and use frequently used items
210   #ご自分でカスタマイズしてください
211   #Please customize it yourself
212   set listSymbolName to {"applescript.fill", "apple.logo", "apple.classical.pages.fill", "gear", "gearshape.2.fill", "globe.badge.chevron.backward", "icloud.and.arrow.down.fill", "icloud.and.arrow.up.fill", "finder", "lock.badge.checkmark.fill", "receipt.fill", "envelope.open.fill", "printer.filled.and.paper", "photo.fill", "wrench.and.screwdriver.fill", "square.2.layers.3d.fill"} as list
213   ##今日の日付合字版
214   set listResponse to doGetTodayString()
215   set beginning of listSymbolName to (first item of listResponse)
216   set beginning of listSymbolName to (last item of listResponse)
217   ######################
218   #フォルダをタグに基づいて色合い調整 設定を有効にする
219   #Disable Tag Based Icon Tinting をFalseにして設定を有効にする
220   set ocidGlobalDomain to refMe's NSUserDefaults's alloc()'s initWithSuiteName:(".GlobalPreferences")
221   set ocidGlobalDomainDict to ocidGlobalDomain's dictionaryRepresentation()
222   set ocidKeyArray to ocidGlobalDomainDict's allKeys()
223   set boolContain to ocidKeyArray's containsObject:("AppleDisableTagBasedIconTinting")
224   #分岐は不要だったけどせっかく書いたので残す
225   #I didn't need a branch, but I wrote it, so I'll leave it.
226   if (boolContain as boolean) is false then
227      #設定済みなので何もしない
228      #I don't do anything because it's already set up
229      set boolDidChange to false as boolean
230   else if boolContain is true then
231      ocidGlobalDomain's removeObjectForKey:("AppleDisableTagBasedIconTinting")
232      ocidGlobalDomain's synchronize()
233      set boolDidChange to true as boolean
234   end if
235   
236   ######################
237   #ロケールの値でメッセージを分岐する
238   set appLocale to refMe's NSLocale's currentLocale()
239   set ocidLocaleID to appLocale's objectForKey:(refMe's NSLocaleIdentifier)
240   set ocidCountryCode to appLocale's objectForKey:(refMe's NSLocaleCountryCode)
241   set ocidLanguageCode to appLocale's objectForKey:(refMe's NSLocaleLanguageCode)
242   set strLocaleID to ocidLocaleID as text
243   set strCountryCode to ocidCountryCode as text
244   set strLanguageCode to ocidLanguageCode as text
245   #国旗絵文字取得
246   #Get the national flag emoji
247   set ocidFlagEmoji to doGetCountryCode2EmojiFlag(ocidCountryCode)
248   
249   
250   ################################
251   #【1】OSのデフォルトタグ名を収集する
252   # 各国語でのタグ名のデフォルト値の取得
253   set strAppFilePath to "/System/Library/CoreServices/Finder.app" as text
254   set ocidAppFilePathStr to refMe's NSString's stringWithString:(strAppFilePath)
255   set ocidAppFilePath to ocidAppFilePathStr's stringByStandardizingPath()
256   set ocidAppFilePathURL to refMe's NSURL's fileURLWithPath:(ocidAppFilePath) isDirectory:(true)
257   set appFineder to refMe's NSBundle's bundleWithURL:(ocidAppFilePathURL)
258   #localizedStringForKeyは
259   #en英語のLPROJのキーと値を入れます
260   set ocidNoColor to appFineder's localizedStringForKey:("TG_COLOR_0") value:("No Color") table:("LocalizableMerged")
261   set ocidGray to appFineder's localizedStringForKey:("TG_COLOR_1") value:("Gray") table:("LocalizableMerged")
262   set ocidGreen to appFineder's localizedStringForKey:("TG_COLOR_2") value:("Green") table:("LocalizableMerged")
263   set ocidPurple to appFineder's localizedStringForKey:("TG_COLOR_3") value:("Purple") table:("LocalizableMerged")
264   set ocidBlue to appFineder's localizedStringForKey:("TG_COLOR_4") value:("Blue") table:("LocalizableMerged")
265   set ocidYellow to appFineder's localizedStringForKey:("TG_COLOR_5") value:("Yellow") table:("LocalizableMerged")
266   set ocidRed to appFineder's localizedStringForKey:("TG_COLOR_6") value:("Red") table:("LocalizableMerged")
267   set ocidOrange to appFineder's localizedStringForKey:("TG_COLOR_7") value:("Orange") table:("LocalizableMerged")
268   #カラー無し 
269   set strIndex0 to ocidNoColor as text
270   #グレイ Gray
271   set strIndex1 to ocidGray as text
272   #グリーン Green
273   set strIndex2 to ocidGreen as text
274   #パープル Purple
275   set strIndex3 to ocidPurple as text
276   #ブルー Blue
277   set strIndex4 to ocidBlue as text
278   #イエロー Yellow
279   set strIndex5 to ocidYellow as text
280   #レッド Red
281   set strIndex6 to ocidRed as text
282   #オレンジ Orange
283   set strIndex7 to ocidOrange as text
284   #ラベル無しの場合
285   set strSetNoSelect to (strIndex0) as text
286   
287   ################################
288   #【2】com.apple.sharedfilelistの値を収集する
289   set ocidURLsArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
290   set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject()
291   set ocidContainerPathURL to ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("com.apple.sharedfilelist") isDirectory:(true)
292   set strFileName to ("com.apple.LSSharedFileList.ProjectsItems.sfl4") as text
293   set ocidSharedFileListURL to ocidContainerPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
294   #osascriptからアクセスするためにまずコピーする
295   set appFileManager to refMe's NSFileManager's defaultManager()
296   set ocidTempDirURL to appFileManager's temporaryDirectory()
297   set ocidUUID to refMe's NSUUID's alloc()'s init()
298   set ocidUUIDString to ocidUUID's UUIDString
299   set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
300   #コピー先フォルダを作成して
301   set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
302   ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
303   set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
304   #パスを定義
305   set strFileName to "com.apple.LSSharedFileList.ProjectsItems.sfl4" as text
306   set ocidTempFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
307   #コピー
308   set listDone to (appFileManager's copyItemAtURL:(ocidSharedFileListURL) toURL:(ocidTempFilePathURL) |error|:(reference))
309   
310   #NSKeyedUnarchiver
311   #この方法が正しいのか?わからないが取得できているので良しとする
312   set ocidOption to (refMe's NSDataReadingMappedIfSafe)
313   set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidTempFilePathURL) options:(ocidOption) |error|:(reference)
314   set ocidReadData to (first item of listResponse)
315   
316   ######################
317   #ProjectsItemsから値が取れなかった場合
318   #稀だけどファイル自体がない場合がある
319   if ocidReadData = (missing value) then
320      
321      set listIndex to {strIndex0, strIndex1, strIndex2, strIndex3, strIndex4, strIndex5, strIndex6, strIndex7} as list
322      set ocidNameArray to refMe's NSArray's arrayWithArray:(listIndex)
323      set ocidIndexDict to refMe's NSMutableDictionary's alloc()'s init()
324      ocidIndexDict's setObject:(0) forKey:(strIndex0)
325      ocidIndexDict's setObject:(1) forKey:(strIndex1)
326      ocidIndexDict's setObject:(2) forKey:(strIndex2)
327      ocidIndexDict's setObject:(3) forKey:(strIndex3)
328      ocidIndexDict's setObject:(4) forKey:(strIndex4)
329      ocidIndexDict's setObject:(5) forKey:(strIndex5)
330      ocidIndexDict's setObject:(6) forKey:(strIndex6)
331      ocidIndexDict's setObject:(7) forKey:(strIndex7)
332      
333      ######################
334      #com.apple.sharedfilelistからタグ名を収集できた場合
335   else if ocidReadData ≠ (missing value) then
336      set ocidSetArray to refMe's NSMutableArray's alloc()'s init()
337      ocidSetArray's addObject:(refMe's NSObject's class)
338      ocidSetArray's addObject:(refMe's NSKeyedArchiver's class)
339      ocidSetArray's addObject:(refMe's NSArray's class)
340      set ocidClassSet to refMe's NSSet's setWithArray:(ocidSetArray)
341      set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClasses:(ocidClassSet) fromData:(ocidReadData) |error|:(reference)
342      set ocidSharedfilelistDict to (first item of listResponse)
343      #LocalizableMergedから収集した形式と同じになるようにする
344      set ocidItemsArray to ocidSharedfilelistDict's objectForKey:("items")
345      set ocidIndexDict to refMe's NSMutableDictionary's alloc()'s init()
346      repeat with itemTagDict in ocidItemsArray
347         set ocidItemName to (itemTagDict's objectForKey:("Name"))
348         set ocidItemIndex to (itemTagDict's valueForKeyPath:("CustomItemProperties.kLSSharedTagFileListItemLabel"))
349         if ocidItemIndex = (missing value) then
350            set ocidItemIndex to 0 as integer
351         end if
352         (ocidIndexDict's setObject:(ocidItemIndex) forKey:(ocidItemName))
353      end repeat
354      set ocidNameArray to (ocidSharedfilelistDict's valueForKeyPath:("items.Name"))
355      set listIndex to ocidNameArray as list
356   end if
357   
358   
359   
360   set strLF to ("" & linefeed & "") as text
361   set strCR to ("" & return & "") as text
362   set strCRLF to ("" & return & linefeed & "") as text
363   set strSpace to ("" & space & "") as text
364   set strTab to ("" & tab & "") as text
365   #日本語のメッセージ
366   #Message in Japanese
367   if strLocaleID is "ja_JP" then
368      set strMes1 to ("フォルダを選んでください" & ocidFlagEmoji & "") as text
369      set strPrompt1 to ("" & strCR & strCR & ocidFlagEmoji & "アイコン設定をするフォルダを選んでください" & strCR & strCR & "") as text
370      set strTitle2 to ("選んでください") as text
371      set strPrompt2 to ("フォルダにセットする" & strCR & "ラベル色" & strCR & "または" & strCR & "タグ名を" & strCR & "ひとつ選んでください") as text
372      set strCancelButton to ("キャンセル") as text
373      set strTitle3 to ("文字入力") as text
374      set strTimeUP to ("時間切れですやりなおしてください") as text
375      set strUserCancel to ("ユーザによってキャンセルされました。") as text
376      set strReturn to ("処理終了") as text
377      set strOsMes to ("macOS26以下では結果が反映されませんが実行できます。" & strCR & "OKで処理を継続します") as text
378      set strListButton to ("リストから選ぶ") as text
379      set strPrompt3 to ("SF Symbolの『シンボル名』か『文字』を入力してください" & strCR & "シンボル名は1つかリストから選択できます" & strCR & "文字の場合は絵文字または通常の文字が入力できます" & strCR & "通常の文字の場合、文字数が多くなると文字サイズが小さくなります" & strCR & "例" & strCR & ocidFlagEmoji & ocidCountryCode & strCR & "applescript.fill" & strCR & "✈️羽田") as text
380      set strTitle4 to ("選んでください") as text
381      set strPrompt4 to ("フォルダにセットするSymbolsの名称をえらんでください") as text
382   else
383      #英語のメッセージ
384      #English message
385      set strMes1 to ("Choose Folder" & ocidFlagEmoji & "") as text
386      set strPrompt1 to ("" & strCR & strCR & ocidFlagEmoji & "Select the folder to apply the icon setting" & strCR & strCR & "") as text
387      set strTitle2 to ("Choose Color") as text
388      set strPrompt2 to ("Choose one color" & strCR & "tag Name" & strCR & " to apply to the folder") as text
389      set strCancelButton to ("Cancel") as text
390      set strTitle3 to ("Text Input") as text
391      set strTimeUP to ("Timeout ― please try again") as text
392      set strUserCancel to ("Canceled by user") as text
393      set strReturn to ("Done") as text
394      set strOsMes to ("The result is not reflected on macOS 26 or earlier.") as text
395      set strListButton to ("Choose List") as text
396      set strTitle4 to ("Choose one symbol name") as text
397      set strPrompt3 to ("Enter an SF Symbol Name or a Character" & strCR & "SF Symbol: You can select a symbol name from a list or enter a single one" & strCR & "Character: An emoji or regular text. Longer regular text input will result in a smaller character size." & strCR & "Example" & strCR & ocidFlagEmoji & ocidCountryCode & strCR & "applescript.fill" & strCR & "🇺🇸IA") as text
398      #🇺🇸IA because I am a fan of Caitlin Clark , Go! Caitlin Go!22
399      set strPrompt4 to ("Select Symbol" & strCR & "Please choose the SF Symbol to apply to the folder.") as text
400   end if
401   #############################
402   # OSのバージョン
403   # version of macOS
404   set ocidProcessInfo to refMe's NSProcessInfo's processInfo()
405   set listOsVersion to ocidProcessInfo's operatingSystemVersion()
406   set numMajorVersion to (first item of listOsVersion) as integer
407   set numMinorVersion to (2nd item of listOsVersion) as integer
408   set numPatchVersion to (last item of listOsVersion) as integer
409   if numMajorVersion < 26 then
410      try
411         tell application "System Events"
412            activate
413            set recordResponse to (display alert strOsMes buttons {"OK"} default button "OK" as critical giving up after 10) as record
414         end tell
415      on error strErrMes number numErrNo
416         log doUiCleaning()
417         log strErrMes
418         return false
419      end try
420      #   return false
421   end if
422   #############################
423   #ラベルインデックスの色を選ぶ
424   # Choose the label index color
425   try
426      tell application "System Events"
427         activate
428         set valueResponse to (choose from list listIndex with title strTitle2 with prompt strPrompt2 default items (last item of listIndex) OK button name "OK" cancel button name strCancelButton with empty selection allowed without multiple selections allowed)
429      end tell
430   on error strErrMes number numErrNo
431      #プロセスクリーニングしてから終了
432      #Finish after process cleaning
433      log doUiCleaning()
434      log strErrMes
435      return false
436   end try
437   if (class of valueResponse) is boolean then
438      #プロセスクリーニングしてから終了
439      #Finish after process cleaning
440      log doUiCleaning()
441      log strUserCancel
442      return false
443   else if (class of valueResponse) is list then
444      #戻り値が空の場合はラベルインデックスは0を設定する
445      #If the return value is empty, set the label index to 0
446      if valueResponse is {} then
447         set strIndexName to strSetNoSelect as text
448      else
449         set strIndexName to (first item of valueResponse) as text
450      end if
451   end if
452   #インデックスの番号
453   # Index number
454   set ocidIndexNO to ocidIndexDict's valueForKey:(strIndexName)
455   #基本的には発生しないはずだけどエラーよけに残す
456   #ラベル番号がない場合はラベルインデックス0を指定する
457   if ocidIndexNO = (refMe's NSNull's |null|) then
458      set numIndexNO to 0 as integer
459   else if ocidIndexNO = (missing value) then
460      set numIndexNO to 0 as integer
461   else
462      set numIndexNO to ocidIndexNO as integer
463   end if
464   log numIndexNO as text
465   #############################
466   #文字を入力 ダイアログ
467   # Text input dialog
468   set appPasteboard to refMe's NSPasteboard's generalPasteboard()
469   set ocidValue to appPasteboard's stringForType:(refMe's NSPasteboardTypeString)
470   if ocidValue = (missing value) then
471      set strDefaultAnswer to ("applescript.fill") as text
472   else
473      set strDefaultAnswer to ocidValue as text
474   end if
475   #ダイアログ
476   #display dialog
477   set aliasIconPath to (POSIX file "/System/Library/PrivateFrameworks/StorageManagement.framework/PlugIns/AppleInternalStorageExtension.appex/Contents/Resources/AppleInternalIcon.icns") as alias
478   try
479      tell application "System Events"
480         activate
481         set recordResponse to (display dialog strPrompt3 with title strTitle3 default answer strDefaultAnswer buttons {"OK", strCancelButton, strListButton} default button "OK" cancel button strCancelButton with icon aliasIconPath giving up after 120 without hidden answer)
482      end tell
483   on error strErrMes number numErrNo
484      #プロセスクリーニングしてから終了
485      #Finish after process cleaning
486      log doUiCleaning()
487      log strErrMes
488      return false
489   end try
490   if true is equal to (gave up of recordResponse) then
491      #プロセスクリーニングしてから終了
492      #Finish after process cleaning
493      log doUiCleaning()
494      log strTimeUP
495      return false
496   end if
497   if "OK" is equal to (button returned of recordResponse) then
498      set strResponse to (text returned of recordResponse) as text
499      #SF Symbolsの名称をリストから選択
500      #Select the name of SF Symbols from the list
501   else if strListButton is equal to (button returned of recordResponse) then
502      try
503         tell application "System Events"
504            activate
505            set valueResponse to (choose from list listSymbolName with title strTitle4 with prompt strPrompt4 default items (last item of listSymbolName) OK button name "OK" cancel button name strCancelButton with empty selection allowed without multiple selections allowed)
506         end tell
507      on error strErrMes number numErrNo
508         #プロセスクリーニングしてから終了
509         #Finish after process cleaning
510         log doUiCleaning()
511         log strErrMes
512         return false
513      end try
514      if (class of valueResponse) is boolean then
515         #プロセスクリーニングしてから終了
516         #Finish after process cleaning
517         log doUiCleaning()
518         log strUserCancel
519         return false
520      else if (class of valueResponse) is list then
521         #文字を入力しない シンボル名も選択しない =文字不要
522         #Do not enter characters Do not select symbol names = no characters required
523         if valueResponse is {} then
524            set strResponse to "" as text
525         else
526            set strResponse to (first item of valueResponse) as text
527         end if
528      end if
529   else
530      #プロセスクリーニングしてから終了
531      #Finish after process cleaning
532      log doUiCleaning()
533      log strUserCancel
534      return false
535   end if
536   #タブと改行とスペースを除去しておきます
537   # Remove tabs and newlines
538   set ocidSetChar to refMe's NSString's stringWithString:(strResponse)
539   set ocidSetChar to (ocidSetChar's stringByReplacingOccurrencesOfString:(strCR) withString:(""))
540   set ocidSetChar to (ocidSetChar's stringByReplacingOccurrencesOfString:(strLF) withString:(""))
541   set ocidSetChar to (ocidSetChar's stringByReplacingOccurrencesOfString:(strTab) withString:(""))
542   #スペース除去は色々考えた結果処理することにした
543   #After thinking about it, I decided to process the space removal.
544   set ocidSetChar to (ocidSetChar's stringByReplacingOccurrencesOfString:(strSpace) withString:(""))
545   #文字数が0ならラベルインデックスの処理だけ行う
546   #If the number of characters is 0, only the label index will be processed.
547   set strResponse to ocidSetChar as text
548   set numCntResponseText to (count of (every character of strResponse)) as integer
549   if numCntResponseText = 0 then
550      set boolCharNeed to false as boolean
551   else
552      set boolCharNeed to true as boolean
553   end if
554   
555   #入力値がSF Symbolの名称か?判定
556   #Is the input value the name of SF Symbol? chack
557   set boolChkOK to doChkSymbolName(ocidSetChar)
558   #SF Symbolでない場合は最大文字数を10文字にする
559   #If it is not a SF Symbol, set the maximum number of characters to 10 characters
560   if boolChkOK is false then
561      #いったんテキストに戻して見た目の文字数で取り出すことにした
562      #I decided to return it to the text and take it out by the number of characters it looks like.
563      set strSetChar to ocidSetChar as text
564      set numCntChar to (count of character of strSetChar) as integer
565      if numCntChar = 0 then
566         set str10Text to ("") as text
567      else if numCntChar < 10 then
568         set str10Text to (characters 1 through numCntChar of strSetChar) as text
569      else
570         set str10Text to (characters 1 through 10 of strSetChar) as text
571      end if
572      set ocidSetChar to refMe's NSString's stringWithString:(str10Text)
573   end if
574   #############################
575   #入力された文字をJSONをファイルにする
576   # Convert the entered text into a JSON file
577   set ocidTempDirURL to appFileManager's temporaryDirectory()
578   set ocidUUID to refMe's NSUUID's alloc()'s init()
579   set ocidUUIDString to ocidUUID's UUIDString
580   set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
581   set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
582   ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
583   set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
584   #ファイルパス
585   #JSON SAVE file Path
586   set strFileName to "com.apple.icon.folder.json" as text
587   set ocidSaveJsonFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
588   set strSaveJsonFilePath to ocidSaveJsonFilePathURL's |path|() as text
589   #JSON用DICT
590   set ocidJsonDict to refMe's NSMutableDictionary's alloc()'s init()
591   #############
592   if boolChkOK is true then
593      ocidJsonDict's setObject:(ocidSetChar) forKey:("sym")
594   else if boolChkOK is false then
595      ocidJsonDict's setObject:(ocidSetChar) forKey:("emoji")
596   end if
597   #NSJSONSerialization
598   set ocidOption to (refMe's NSJSONReadingJSON5Allowed)
599   set listResponse to (refMe's NSJSONSerialization's dataWithJSONObject:(ocidJsonDict) options:(ocidOption) |error|:(reference))
600   set ocidSaveData to (first item of listResponse)
601   ##NSDATA
602   set ocidOption to (refMe's NSDataWritingAtomic)
603   set listDone to ocidSaveData's writeToURL:(ocidSaveJsonFilePathURL) options:(ocidOption) |error|:(reference)
604   #############################
605   #次工程に処理を依頼
606   repeat with itemFolderURL in ocidFolderURLArray
607      doAppndIcon(itemFolderURL, strSaveJsonFilePath, numIndexNO, strIndexName, boolCharNeed, boolDidChange)
608   end repeat
609   try
610      with timeout of 3 seconds
611         tell application "System Events" to quit
612      end timeout
613   on error strErrMes number numErrNo
614      log "Interrupt and end" & strErrMes & numErrNo
615      return false
616   end try
617   return true
618end open
619
620
621#############################
622#今日の日付合字
623to doGetTodayString()
624   #月レコード
625   set recordMonth to {|01|:"", |02|:"", |03|:"", |04|:"", |05|:"", |06|:"", |07|:"", |08|:"", |09|:"", |10|:"", |11|:"", |12|:""} as record
626   set ocidMonthDict to refMe's NSMutableDictionary's alloc()'s initWithDictionary:(recordMonth)
627   #日レコード
628   set recordDate to {|01|:"", |02|:"", |03|:"", |04|:"", |05|:"", |06|:"", |07|:"", |08|:"", |09|:"", |10|:"", |11|:"", |12|:"", |13|:"", |14|:"", |15|:"", |16|:"", |17|:"", |18|:"", |19|:"", |20|:"", |21|:"", |22|:"", |23|:"", |24|:"", |25|:"", |26|:"", |27|:"", |28|:"", |29|:"", |30|:"", |31|:""} as record
629   set ocidDateDict to refMe's NSMutableDictionary's alloc()'s initWithDictionary:(recordDate)
630   #
631   set ocidDate to refMe's NSDate's |date|()
632   set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
633   ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
634   ocidNSDateFormatter's setDateFormat:("yyyyMMdd")
635   set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
636   set strDateAndTime to ocidDateAndTime as text
637   ocidNSDateFormatter's setDateFormat:("EEE")
638   set ocidWeekDay to ocidNSDateFormatter's stringFromDate:(ocidDate)
639   ocidNSDateFormatter's setDateFormat:("dd")
640   set ocidDayNo to ocidNSDateFormatter's stringFromDate:(ocidDate)
641   set ocidDateValue to ocidDateDict's objectForKey:(ocidDayNo)
642   ocidNSDateFormatter's setDateFormat:("MM")
643   set ocidMonthNo to ocidNSDateFormatter's stringFromDate:(ocidDate)
644   set ocidMonthValue to ocidMonthDict's objectForKey:(ocidMonthNo)
645   set ocidSetJsonValue to ocidMonthValue's stringByAppendingString:(ocidDateValue)
646   ocidNSDateFormatter's setDateFormat:("d")
647   set ocidDayNo to ocidNSDateFormatter's stringFromDate:(ocidDate)
648   set strSFdate to ("" & ocidDayNo & ".calendar") as text
649   set strSetJsonValue to ocidSetJsonValue as text
650   set listReturn to {strSetJsonValue, strSFdate} as list
651   return listReturn
652   
653end doGetTodayString
654
655#############################
656#アイコン付与するメインプロセス
657to doAppndIcon(ocidDirPathURL, strSaveJsonFilePath, numIndexNO, strIndexName, boolCharNeed, boolDidChange)
658   #############################
659   #フォルダにインデックスを付ける
660   # Assign an index color to the folder
661   #ラベルのインデクス番号
662   # Label index number
663   set ocidLabelNo to (refMe's NSNumber's numberWithInteger:(numIndexNO))
664   #順番に処理
665   # Process in sequence
666   #ラベルをつける
667   #Attach a label index no
668   #   set listResult to (ocidDirPathURL's setResourceValue:(ocidLabelNo) forKey:(refMe's NSURLLabelNumberKey) |error|:(reference))
669   #PLIST 本処理
670   #PLIST Main Process
671   #1秒まってから次の処理
672   # Wait 1 second before proceeding Magic 1 Second
673   delay numMagicTime
674   
675   #現在のタグを取得して
676   set ocidKey to (refMe's NSURLTagNamesKey)
677   set listResponse to (ocidDirPathURL's getResourceValue:(reference) forKey:(ocidKey) |error|:(reference))
678   set ocidTagNameArray to (2nd item of listResponse)
679   if ocidTagNameArray = (missing value) then
680      set ocidTagArray to refMe's NSMutableArray's alloc()'s init()
681   else
682      set ocidTagArray to ocidTagNameArray's mutableCopy()
683   end if
684   
685   #まずタグをつけます
686   # Add tags first
687   #タグのDICTとARRAY
688   # Create tag DICT and ARRAY
689   set ocidTagName to (refMe's NSString's stringWithString:(strIndexName))
690   (ocidTagArray's addObject:(ocidTagName))
691   set ocidSetDict to refMe's NSMutableDictionary's alloc()'s init()
692   (ocidSetDict's setObject:(ocidTagArray) forKey:(refMe's NSURLTagNamesKey))
693   #フォルダにタグをつける場合は
694   # When adding tags to a folder:
695   if numIndexNO0 then
696      #タグを付与して
697      #   - Apply tags
698      #   set listDone to (ocidDirPathURL's setResourceValues:(ocidTagArray) |error|:(reference))
699      set ocidKey to (refMe's NSURLTagNamesKey)
700      set listDone to (ocidDirPathURL's setResourceValue:(ocidTagArray) forKey:(ocidKey) |error|:(reference))
701      
702      #0の場合はタグを除去する
703      #   - If set to 0, remove the tag
704   else if numIndexNO = 0 then
705      set ocidNullArray to refMe's NSArray's alloc()'s init()
706      set ocidKey to (refMe's NSURLTagNamesKey)
707      set listDone to (ocidDirPathURL's setResourceValue:(ocidNullArray) forKey:(ocidKey) |error|:(reference))
708   end if
709   
710   
711   #1秒まってから次の処理
712   # Wait 1 second before proceeding Magic 1 Second
713   delay numMagicTime
714   #Finderでフォルダの内容を更新する
715   # Refresh folder contents in Finder
716   set aliasDirPath to (ocidDirPathURL's absoluteURL()) as alias
717   tell application "Finder"
718      tell folder aliasDirPath
719         update
720      end tell
721   end tell
722   
723   #1秒まってから次の処理
724   # Wait 1 second before proceeding Magic 1 Second
725   delay numMagicTime
726   
727   #############################
728   #JSONファイルを拡張属性を設定
729   #Set extended attributes for JSON files
730   #パス
731   set ocidDirPath to ocidDirPathURL's |path|()
732   set strFolderPath to ocidDirPath as text
733   #####com.apple.icon.folder#S
734   #拡張属性のcom.apple.icon.folderにJSONを入れます
735   # Insert JSON into the extended attribute com.apple.icon.folder
736   ######
737   #ダイアログで文字入力がなかった場合
738   if boolCharNeed is false then
739      #何もしない
740   else if boolCharNeed is true then
741      #パスのエスケープ
742      set strFolderPath to doPathEscape(strFolderPath)
743      set strSaveJsonFilePath to doPathEscape(strSaveJsonFilePath)
744      #文字入力があれば処理する
745      #   set strCmdText to ("/usr/bin/xattr -x -w com.apple.icon.folder#S \"$(/usr/bin/xxd -p \"" & strSaveJsonFilePath & "\" | tr -d \"\\\n\")\" \"" & strFolderPath & "\"") as text
746      #ZSHに変更
747      set strCmdText to "/bin/zsh -c \"/usr/bin/xattr -x -w com.apple.icon.folder#S \\\"\\$(/usr/bin/xxd -p \\\"" & strSaveJsonFilePath & "\\\" | tr -d \\\"\\\\\n\\\")\\\" \\\"" & strFolderPath & "\\\"\""
748      try
749         do shell script strCmdText
750      on error strErrMes number numErrNo
751         #プロセスクリーニングしてから終了
752         #Finish after process cleaning
753         log doUiCleaning()
754         log strCmdText & strErrMes
755         return false
756      end try
757      
758      #com.apple.FinderInfo
759      #com.apple.FinderInfoを更新することでアイコンの表示が反映されます
760      # Updating com.apple.FinderInfo reflects the icon change
761      
762      try
763         set strCmdText to ("/usr/bin/xcode-select -p") as text
764         do shell script strCmdText
765         #--> ここでエラーしても大丈夫なんだけど
766         set strCmdText to ("/bin/zsh -c \"/usr/bin/SetFile -a C \\\"" & strFolderPath & "\\\"\"")
767         do shell script strCmdText
768      on error strErrMes number numErrNo
769         #プロセスクリーニングしてから終了
770         #Finish after process cleaning
771         log doUiCleaning()
772         log strCmdText & strErrMes
773         return false
774      end try
775   end if
776   
777   #更新通知を送る
778   # Send update notification
779   set appWorkspace to refMe's NSWorkspace's sharedWorkspace()
780   #更新
781   (appWorkspace's noteFileSystemChanged:(ocidDirPath))
782   
783   
784   #UIプロセスを終了させる
785   #KIll the UI process
786   log doUiCleaning()
787   
788   #NSUserDefaultsの設定変更をしていたらFinderを再起動させる
789   #If NSUserDefaults have changed the settings, restart the Finder
790   if boolDidChange is true then
791      do shell script "/bin/zsh -c '/usr/bin/killall Finder'"
792   end if
793   return true
794end doAppndIcon
795
796
797########################
798#パスのエスケープ
799to doPathEscape(strFilePath)
800   set strFilePath to strFilePath as text
801   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
802   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
803   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
804   set listEscChar to {"\\", "\"", "$", "`"} as list
805   repeat with itemEscChar in listEscChar
806      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\\\\\" & itemEscChar & ""))
807   end repeat
808   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\\\"'!'\\\""))
809   
810   return ocidFilePath
811end doPathEscape
812
813############################
814#UIを終了させる
815# Terminate UI
816(*
817osascriptで実行する場合(スクリプトメニューからとかzsh実行とか)
818実行後に自然終了する事もあるのですが
819Open and Save Panel Service(SystemUIServer)
820com.apple.appkit.xpc.openAndSavePanelService
821
822QuickLookUIService(SystemUIServer)
823com.apple.quicklook.QuickLookUIServiceのプロセスが残ります
824HUPを送ることで自然終了するようにしました
825判定は簡易で
826osascriptよりPIDが大きい(後から呼び出された)
827Open and Save Panel Serviceをkill -HUPします
828
829Clean up leftover macOS services after osascript execution.
830
831When executed via osascript (e.g., from Script Menu or zsh),
832the following processes may remain active:
833- com.apple.appkit.xpc.openAndSavePanelService (Open and Save Panel Service)
834- com.apple.quicklook.QuickLookUIService (QuickLookUIService)
835
836These are "orphaned" processes that can be forced to terminate gracefully
837by sending the HUP signal.
838
839Action: Send HUP signal (kill -HUP) to the Open and Save Panel Service
840with a PID greater than the osascript process (simple check for processes
841called after the script started).
842
843*)
844to doUiCleaning()
845   set strName to (name of current application) as text
846   if strName is "osascript" then
847      log "Start process cleaning"
848      #まずosascriptのPIDを取得します
849      #First, get the PID of osascript
850      try
851         tell current application
852            tell application "System Events"
853               tell application process "osascript"
854                  set numOsascriptPID to unix id as integer
855               end tell
856            end tell
857         end tell
858      on error strErrMes number numErrNo
859         log "Interrupt and end" & strErrMes & numErrNo
860         return false
861      end try
862      #続けて子プロセスのopenAndSavePanelServiceのPIDを取得します
863      #Continue to get the PID of the child process openAndSavePanelService
864      set ocidAppArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.appkit.xpc.openAndSavePanelService"))
865      repeat with itemApp in ocidAppArray
866         set numPID to itemApp's processIdentifier()
867         #osascriptの後に呼び出されたopenAndSavePanelServiceは終了する
868         #openAndSavePanelService called after osascript ends
869         if numOsascriptPID < numPID then
870            set strPID to numPID as text
871            try
872               do shell script ("/bin/zsh -c '/bin/kill -1 " & strPID & "'")
873               #   do shell script ("/bin/zsh -c '/bin/kill -15 " & strPID & "'")
874               #   do shell script ("/bin/zsh -c '/bin/kill -9 " & strPID & "'")
875               #   log itemApp's terminate() as boolean
876               #   log itemApp's forceTerminate() as boolean
877            on error strErrMes number numErrNo
878               log strErrMes & numErrNo
879               return false
880            end try
881         end if
882      end repeat
883      log "Done process cleaning"
884   else
885      log "Nothing Done process cleaning"
886   end if
887   #System Eventsも終了させないと残ることがあります
888   #If you don't end System Events, it may remain.
889   try
890      with timeout of 3 seconds
891         tell application "System Events" to quit
892      end timeout
893   on error strErrMes number numErrNo
894      log "Interrupt and end" & strErrMes & numErrNo
895      return false
896   end try
897   refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications()
898   return true
899end doUiCleaning
900
901
902############################
903#SF Symbolsシンボル名チェッカー
904#SF Symbol name checker
905(*
906SFSymbols.frameworkからシンボル名を収集取得して
907シンボル名として、収集したシンボル名に含まれていれば
908シンボル名として正しい と簡易に判定します
909
910Collect and obtain the symbol name from SFSymbols.framework and simply determine that if it is included in the collected symbol name as a symbol name, it is correct as a symbol name.
911
912CoreGlyphs.bundleとCoreGlyphsPrivate.bundle両方を対象にしました
913CoreGlyphs.bundleとCoreGlyphsPrivate.bundleI targeted both
914
915*)
916to doChkSymbolName(argNameString)
917   #チェック用のArray
918   set ocidSymbolsArray to refMe's NSMutableArray's alloc()'s init()
919   #PLISTのパス
920   set listPlistFilePath to {"/System/Library/PrivateFrameworks/SFSymbols.framework/Versions/A/Resources/CoreGlyphs.bundle/Contents/Resources/name_availability.plist", "/System/Library/PrivateFrameworks/SFSymbols.framework/Versions/A/Resources/CoreGlyphsPrivate.bundle/Contents/Resources/name_availability.plist"} as list
921   repeat with itemPlistFilePath in listPlistFilePath
922      #パス path
923      set strPlistFilePath to (itemPlistFilePath) as text
924      set ocidFilePathStr to (refMe's NSString's stringWithString:(strPlistFilePath))
925      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
926      set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false))
927      #PLISTをDICTで読み込んで
928      #Load PLIST with DICT
929      set listResponse to (refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference))
930      set ocidPlistDict to (first item of listResponse)
931      set ocidItemSymbolsDict to (ocidPlistDict's objectForKey:("symbols"))
932      set ocidAllKeys to ocidItemSymbolsDict's allKeys()
933      #キーの値を格納する
934      #Store the value of the key
935      (ocidSymbolsArray's addObjectsFromArray:(ocidAllKeys))
936   end repeat
937   #チェック check
938   #含まれていれば シンボル名が正しいと判定します
939   #If it is included, it is determined that the symbol name is correct.
940   set boolContain to ocidSymbolsArray's containsObject:(argNameString)
941   #戻し値はBOOL
942   #The return value is BOOL
943   if boolContain is false then
944      return false as boolean
945   else if boolContain is true then
946      return true as boolean
947   end if
948   
949end doChkSymbolName
950
951
952######################
953#カントリーコードから絵文字の旗
954to doGetCountryCode2EmojiFlag(argCountryCode)
955   #念の為テキストにしてから再度NSStringにしておく
956   set strCountryCode to argCountryCode as text
957   set ocidCountryCode to refMe's NSString's stringWithString:(strCountryCode)
958   #オフセット値
959   set ocidOffSetA to refMe's NSString's stringWithString:("A")
960   set uniOffSetA to ocidOffSetA's characterAtIndex:(0)
961   set intOffSetA to uniOffSetA as integer
962   #サローゲートNO
963   set intSurrogateNo to 127462 as integer
964   #キャラクター上位
965   set uniHiChar to ocidCountryCode's characterAtIndex:(0)
966   set intHiCharDec to uniHiChar as integer
967   set intHiInd to (intSurrogateNo + intHiCharDec - intOffSetA) as integer
968   set strHiUniCode to doDec2Hex(intHiInd) as text
969   #キャラクター下位
970   set uniLwChar to ocidCountryCode's characterAtIndex:(1)
971   set intLwCharDec to uniLwChar as integer
972   set intLwInd to (intSurrogateNo + intLwCharDec - intOffSetA) as integer
973   set strLwUniCode to doDec2Hex(intLwInd) as text
974   #ユニコードサロゲートに整形
975   set strUniSurrogate to ("U+" & strHiUniCode & "U+" & strLwUniCode & "") as text
976   set ocidUniSurrogate to refMe's NSString's stringWithString:(strUniSurrogate)
977   set ocidFlagEmoji to (ocidUniSurrogate's stringByApplyingTransform:("Any-Hex/Unicode") |reverse|:(true))
978   #テキストで戻すか?はお好きな方で
979   #      return ocidFlagEmoji
980   return ocidFlagEmoji as Unicode text
981end doGetCountryCode2EmojiFlag
982
983########################
984#10進数を16進数に変換
985to doDec2Hex(argIntNo)
986   #大文字指定(プロパティで指定する場合はここは削除)
987   set boolCaps to true as boolean
988   #10進数-->16進数の変換レコード
989   if boolCaps is true then
990      set recordDec2Hex to {|0|:"0", |1|:"1", |2|:"2", |3|:"3", |4|:"4", |5|:"5", |6|:"6", |7|:"7", |8|:"8", |9|:"9", |10|:"A", |11|:"B", |12|:"C", |13|:"D", |14|:"E", |15|:"F"} as record
991   else
992      set recordDec2Hex to {|0|:"0", |1|:"1", |2|:"2", |3|:"3", |4|:"4", |5|:"5", |6|:"6", |7|:"7", |8|:"8", |9|:"9", |10|:"a", |11|:"b", |12|:"c", |13|:"d", |14|:"e", |15|:"f"} as record
993   end if
994   set ocidDec2HexDict to refMe's NSMutableDictionary's alloc()'s init()
995   ocidDec2HexDict's setDictionary:(recordDec2Hex)
996   #次工程に回す余りを格納するArray
997   set ocidRemArray to refMe's NSMutableArray's alloc()'s init()
998   #引数を数値で再定義して
999   set inteRes to argIntNo as integer
1000   #初回用のあまり値
1001   set numValue to 9999999 as integer
1002   set numDiv to 9999999 as integer
1003   #余りが0になるから値が0になるまで繰り返し
1004   repeat while (numDiv > 0)
1005      #16で割って
1006      set numDiv to (round (inteRes / 16) rounding down) as integer
1007      #余りを
1008      set numValue to inteRes - (numDiv * 16) as integer
1009      #ループの次の回用に再定義
1010      set inteRes to numDiv as integer
1011      #Arrayに加えていく
1012      ocidRemArray's addObject:(numValue)
1013   end repeat
1014   #逆順に並び替えて
1015   set ocidRemArray to (ocidRemArray's reverseObjectEnumerator())'s allObjects()
1016   set ocidHexString to refMe's NSMutableString's alloc()'s init()
1017   (ocidHexString's appendString:("000000"))
1018   #順番に
1019   repeat with itemNo in ocidRemArray
1020      #10進数を
1021      set strItemNo to itemNo as text
1022      #16進数に置き換えて
1023      set strValue to (ocidDec2HexDict's objectForKey:(strItemNo))
1024      (ocidHexString's appendString:(strValue))
1025   end repeat
1026   #ゼロサプレス6桁
1027   set ocidLength to ocidHexString's |length|()
1028   set numStart to (ocidLength - 5) as integer
1029   set ocidRange to refMe's NSRange's NSMakeRange(numStart, 5)
1030   set ocidReturnString to ocidHexString's substringWithRange:(ocidRange)
1031   #HEX値の出来上がりを戻す
1032   return ocidReturnString
1033   
1034end doDec2Hex
1035
AppleScriptで生成しました