macOS内の標準装備のFrameworkの情報を収集するAppleScriptです。AppleScriptからmacOS内のFrameworkを呼ぶには、Framework内にbridgesupportファイルが存在している必要があります。
これまで、さまざまな資料を作成するさいに、Frameworkの有無だけをまとめてきましたが……結局のところ、bridgesupportファイルの有無を調査しないと意味がないのでは? ということで書いてみたものです。
結果は、Framework名、x86版の有無、ARM64E版の有無がCSVファイルで出力されます。
AppleScript名:各Framework内のbridgesupportファイル情報の収集_v2.scptd |
— – Created by: Takaaki Naganoya – Created on: 2024/11/29 — – Copyright © 2024 Piyomaru Software, All Rights Reserved — use AppleScript use framework "Foundation" use scripting additions script spd property a1Res : {} property a2Res : {} property a3Res : {} property allList : {} property fNames : {} end script set outPath to POSIX path of (choose file name with prompt "Input file name (with \".csv\")") –Frameworkフォルダ1から取得 set frPath to "/System/Library/Frameworks/" set s1Text to "find " & frPath & " -name *.framework" set (a1Res of spd) to paragraphs of (do shell script s1Text) set osV to my numToHex((system attribute "sysv"), 4) if osV ≥ "1200" then –Frameworkフォルダ2から取得 set frPath to "/System/DriverKit/System/Library/Frameworks" set s1Text to "find " & frPath & " -name *.framework" set (a2Res of spd) to paragraphs of (do shell script s1Text) –合成 set (a3Res of spd) to (a1Res of spd) & (a2Res of spd) else copy (a1Res of spd) to (a3Res of spd) end if –合成して重複を除去 set aRes to uniquify1DList((a3Res of spd)) of me –フレームワークでループして、bridgesupportファイルをx64とApple Silicon版を検索 set (fNames of spd) to {} repeat with i in aRes set t1Path to (current application’s NSString’s stringWithString:(i)) set t2Path to t1Path’s stringByResolvingSymlinksInPath() –リンクを解消 set tName to t2Path’s lastPathComponent()’s stringByDeletingPathExtension() as string –Find x64 bridgesupport set s1Text to "find " & t2Path & " -name " & tName & ".bridgesupport" try set a1Res to do shell script s1Text on error set a1Res to "" end try –Find Apple Silicon (ARM64E) bridgesupport set s2Text to "find " & t2Path & " -name " & tName & ".arm64e.bridgesupport" try set a2Res to do shell script s2Text on error set a2Res to "" end try –Check result of x64 bridgesupport set ttList to {tName} if a1Res is not equal to "" then set the end of ttList to "●" else set the end of ttList to "" end if –Check result of Apple Silicon (ARM64E) bridgesupport if a2Res is not equal to "" then set the end of ttList to "●" else set the end of ttList to "" end if –Store Results if tName is not in (fNames of spd) then –重複出力を防ぐ set the end of (allList of spd) to ttList set the end of (fNames of spd) to tName end if end repeat –結果のCSV書き出し set sRes to saveAsCSV((allList of spd), outPath) of me on numToHex(theNumber, stringLength) set hexString to {} repeat with i from stringLength to 1 by -1 set hexString to ((theNumber mod 16) as string) & hexString set theNumber to theNumber div 16 end repeat return (hexString as string) end numToHex on getFileSizeFromPath(aPath) set aaPath to current application’s NSString’s stringWithString:(aPath) set aaaPath to aaPath’s stringByResolvingSymlinksInPath() –リンクを解消 set aFM to current application’s NSFileManager’s defaultManager() set anAttr to aFM’s attributesOfItemAtPath:(aaaPath) |error|:(missing value) set sRes to anAttr’s fileSize() return sRes as string end getFileSizeFromPath –文字置換 on repChar(origText as string, targChar as string, repChar as string) set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to targChar set tmpList to text items of origText set AppleScript’s text item delimiters to repChar set retText to tmpList as string set AppleScript’s text item delimiters to curDelim return retText end repChar –2D List to CSV file on saveAsCSV(aList, aPath) –set crlfChar to (ASCII character 13) & (ASCII character 10) set crlfChar to (string id 13) & (string id 10) set LF to (string id 10) set wholeText to "" repeat with i in aList set newLine to {} –Sanitize (Double Quote) repeat with ii in i set jj to ii as text set kk to repChar(jj, string id 34, (string id 34) & (string id 34)) of me –Escape Double Quote set the end of newLine to kk end repeat –Change Delimiter set aLineText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to "\",\"" set aLineList to newLine as text set AppleScript’s text item delimiters to curDelim set aLineText to repChar(aLineList, return, "") of me –delete return set aLineText to repChar(aLineText, LF, "") of me –delete lf set wholeText to wholeText & "\"" & aLineText & "\"" & crlfChar –line terminator: CR+LF end repeat if (aPath as string) does not end with ".csv" then set bPath to aPath & ".csv" as Unicode text else set bPath to aPath as Unicode text end if return writeToFileAsUTF8(wholeText, bPath) of me end saveAsCSV on writeToFileAsUTF8(aStr, aPath) set cStr to current application’s NSString’s stringWithString:aStr set thePath to POSIX path of aPath set aRes to cStr’s writeToFile:thePath atomically:false encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) return aRes as boolean end writeToFileAsUTF8 on uniquify1DList(theList as list) set theSet to current application’s NSOrderedSet’s orderedSetWithArray:theList return (theSet’s array()) as list end uniquify1DList |
More from my site
(Visited 4 times, 4 visits today)