— – Created by: Takaaki Naganoya – Created on: 2024/10/16 — – Copyright © 2024 Piyomaru Software, All Rights Reserved —
use AppleScript version "2.8" use scripting additions use framework "Foundation"
property NSArray : a reference to current application’s NSArray property NSPredicate : a reference to current application’s NSPredicate
set targAppBundleID to "com.apple.ScriptEditor2" set targKey to "CFBundleName" set aLocale to (current application’s NSLocale’s currentLocale())
set locResList to getAppInfoPlistValueInEveryLocalizedLangs(targAppBundleID, targKey, aLocale) of me –> {{"ヘブライ語", "עורך התסריטים"}, {"韓国語", "스크립트 편집기"}, {"インドネシア語", "Editor Skrip"}, {"オランダ語", "Scripteditor"}, {"トルコ語", "Betik Düzenleyici"}, {"フィンランド語", "Skriptieditori"}, {"ハンガリー語", "Szkriptszerkesztő"}, {"ロシア語", "Редактор скриптов"}, {"イタリア語", "Script Editor"}, {"スペイン語(ラテンアメリカ)", "Editor de Scripts"}, {"ギリシャ語", "Επεξεργασία σκριπτ"}, {"カタロニア語", "Editor de Scripts"}, {"フランス語(カナダ)", "Éditeur de script"}, {"中国語(台湾)", "工序指令編寫程式"}, {"中国語(香港)", "程式碼編寫程式"}, {"ポーランド語", "Edytor skryptów"}, {"スウェーデン語", "Skriptredigerare"}, {"ノルウェー語", "Prosedyreredigering"}, {"アラビア語", "محرر البرامج النصية"}, {"英語", "Script Editor"}, {"デンマーク語", "Instruksværktøj"}, {"ヒンディー語", "स्क्रिप्ट संपादक"}, {"タイ語", "ตัวแก้ไขสคริปต์"}, {"中国語(中国本土)", "脚本编辑器"}, {"英語(イギリス)", "Script Editor"}, {"マレー語", "Editor Skrip"}, {"チェコ語", "Editor skriptů"}, {"スロバキア語", "Script Editor"}, {"英語(オーストラリア)", "Script Editor"}, {"スロベニア語", "Skriptni urejevalnik"}, {"ドイツ語", "Skripteditor"}, {"ベトナム語", "Trình soạn thảo tập lệnh"}, {"ポルトガル語(ブラジル)", "Editor de Scripts"}, {"スペイン語", "Editor de Scripts"}, {"ウクライナ語", "Редактор скриптів"}, {"ルーマニア語", "Editor scripturi"}, {"フランス語", "Éditeur de script"}, {"クロアチア語", "Urednik skripte"}, {"ポルトガル語(ポルトガル)", "Editor de Scripts"}, {"日本語", "スクリプトエディタ"}}
on getAppInfoPlistValueInEveryLocalizedLangs(targAppBundleID, targKey, aLocale) script spd property urlList : {} end script –macOS 13以降がターゲット set v1 to system attribute "sys1" –> 10, 11, 12, 13, 14, 15…. if v1 < 13 then error "This Script require macOS 13 or later" –指定アプリのバンドル内のResourceから「InfoPlist.loctable」で終わるファイル名のパスを抽出 tell application "Finder" set defPath to application file id targAppBundleID end tell set defPath to (POSIX path of (defPath as alias)) & "Contents/Resources" –Cocoa流のPOSIX path set fList to getFilesIn(defPath) of me set anArray to NSArray’s arrayWithArray:fList set aPred to NSPredicate’s predicateWithFormat:"SELF ENDSWITH ’InfoPlist.loctable’" set locRes to (anArray’s filteredArrayUsingPredicate:aPred) as list set resList to {} –.loctableファイルでループ(1つだけだが) repeat with i in locRes set j to contents of i set (urlList of spd) to (my readPlistAt:(j)) set langKeys to ((urlList of spd)’s allKeys()) as list –Language Codeでループ repeat with ii in langKeys set jj to contents of ii set aLangDat to ((urlList of spd)’s valueForKey:jj) —plist(=loctable)のlabelでループ set allLangKeys to (aLangDat’s allKeys()) as list repeat with iii in allLangKeys set jjj to contents of iii set aVal to (aLangDat’s valueForKey:(jjj)) if jjj = targKey then set locLangName to getLangNameWithLocale(jj, aLocale) of me set the end of resList to {locLangName, aVal as string} exit repeat end if end repeat end repeat end repeat return resList end getAppInfoPlistValueInEveryLocalizedLangs
–Read Plist on readPlistAt:thePath set thePath to current application’s NSString’s stringWithString:thePath set thePath to thePath’s stringByExpandingTildeInPath() set theDict to current application’s NSDictionary’s dictionaryWithContentsOfFile:thePath return theDict end readPlistAt:
–指定フォルダ内のファイルのフルパス一覧を返す on getFilesIn(posixPath) script spd property allItems : {} end script set allItems of spd to {} — make URL set theNSURL to current application’s |NSURL|’s fileURLWithPath:posixPath — make file manager set theNSFileManager to current application’s NSFileManager’s new() — get URL enumerator set theNSFileEnumerator to theNSFileManager’s enumeratorAtURL:theNSURL includingPropertiesForKeys:{current application’s NSURLIsDirectoryKey, current application’s NSURLIsPackageKey} options:((current application’s NSDirectoryEnumerationSkipsPackageDescendants) + (current application’s NSDirectoryEnumerationSkipsHiddenFiles as integer)) errorHandler:(missing value) — get all items from enumerator set (allItems of spd) to theNSFileEnumerator’s allObjects() set theFolders to {} — to store folders — loop through repeat with i from 1 to count of (allItems of spd) — is it a directory? set {theResult, isDirectory} to ((item i of (allItems of spd))’s getResourceValue:(reference) forKey:(current application’s NSURLIsDirectoryKey) |error|:(missing value)) if isDirectory as boolean = false then set {theResult, isPackage} to ((item i of (allItems of spd))’s getResourceValue:(reference) forKey:(current application’s NSURLIsPackageKey) |error|:(missing value)) — is it not a package? if not isPackage as boolean then set end of theFolders to (item i of (allItems of spd))’s |path|() as string –«class furl» end if end if end repeat return theFolders end getFilesIn
on getLangNameWithLocale(langCode, aLocale) set aLangName to (aLocale’s displayNameForKey:(current application’s NSLocaleIdentifier) value:langCode) as string return aLangName end getLangNameWithLocale
|