オープンソースのZipZapをCocoa Framework化したものを呼び出して、指定のZipアーカイブをメモリ上で展開し、指定ファイルの内容を取り出すAppleScriptです。
–> ZipZap.framework(To ~/Library/Frameworks/)
ZipアーカイブでAppleScriptを固めておいて、XcodeのAppleScriptアプリケーションのプロジェクト中に入れておき、指定ファイルのScriptをZipアーカイブから取り出して実行するときに使っています。
ZipZapはXcode Projectに入れてよし、Cocoa Frameworkに入れて呼び出してよし、と自分にとってたいへんに使い勝手のよい部品であり、重要なパーツになっています。
AppleScript名:ZipZapで指定アーカイブをメモリ上で展開して指定ファイルのみ取り出す |
— Created 2019-01-11 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "ZipZap" –https://github.com/pixelglow/ZipZap use framework "OSAKit" use BPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html property |NSURL| : a reference to current application’s |NSURL| property ZZArchive : a reference to current application’s ZZArchive property OSAScript : a reference to current application’s OSAScript set anArchive to POSIX path of (choose file of type {"public.zip-archive"}) set aRes to extractArchiveAndPickupAFile(anArchive, "", "02_script.scpt") of me on extractArchiveAndPickupAFile(aPath, aPass, aTargFileName) set oldArchive to ZZArchive’s archiveWithURL:(|NSURL|’s fileURLWithPath:aPath) |error|:(missing value) set aList to oldArchive’s entries() as list set outList to {} repeat with i in aList set encF to i’s encrypted() as boolean set aFileName to (i’s fileName()) if (aFileName as string) = aTargFileName then set aExt to (aFileName’s pathExtension()) as string set aUTI to my retFileFormatUTI(aExt) set aData to (i’s newDataWithError:(missing value)) –Uncompressed raw data if aData = missing value then set aData to (i’s newDataWithPassword:(aPass) |error|:(missing value)) if aData is equal to (missing value) then return false end if end if if aUTI = "public.plain-text" then –Plain Text set aStr to (NSString’s alloc()’s initWithData:aData encoding:(NSUTF8StringEncoding)) as string else if aUTI = "com.apple.applescript.script" then –AppleScript .scpt file set aScript to (OSAScript’s alloc()’s initWithCompiledData:aData |error|:(missing value)) set aStr to (aScript’s source()) as string end if return aStr end if end repeat end extractArchiveAndPickupAFile on retFileFormatUTI(aExt as string) tell script "BridgePlus" load framework return (current application’s SMSForder’s UTIForExtension:aExt) as string end tell end retFileFormatUTI |
More from my site
(Visited 74 times, 1 visits today)