指定のKeynote書類がフラット形式かバンドル形式かを取得するAppleScriptです。
UTIを取得してみたら簡単に判定できたので、これでいいでしょう。バンドル形式かどうかを判定するために、ディレクトリ構造を仮定したパスを組み立てて、アクセスしてみることも検討したのですが、UTIを求めるだけですみました。
AppleScript名:指定のKeynote書類のタイプを求める.scpt |
— – Created by: Takaaki Naganoya – Created on: 2020/07/05 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set aFilePath to choose file of type {"com.apple.iwork.keynote.key", "com.apple.iwork.keynote.sffkey"} set aUTI to getUTIfromPath(aFilePath) of me –> "com.apple.iwork.keynote.key" (Bundle) –> "com.apple.iwork.keynote.sffkey" (Flat) on getUTIfromPath(anAlias) set aPOSIXpath to POSIX path of anAlias set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath if aURL = missing value then return "" set aRes to aURL’s resourceValuesForKeys:{current application’s NSURLTypeIdentifierKey} |error|:(missing value) if aRes = missing value then return "" return (aRes’s NSURLTypeIdentifierKey) as string end getUTIfromPath |
AppleScript名:指定のKeynote書類のタイプを求める v2.scpt |
— – Created by: Takaaki Naganoya – Created on: 2020/07/05 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set aFilePath to choose file of type {"com.apple.iwork.keynote.key", "com.apple.iwork.keynote.sffkey"} set aUTI to getUTIfromPath(aFilePath) of me set aKType to retKeynoteBundleOrNot(aUTI) of me –> "Flat Keynote" –> "Bundle Package Keynote" on retKeynoteBundleOrNot(anUTI) if anUTI = "com.apple.iwork.keynote.sffkey" then return "Flat Keynote" else if anUTI = "com.apple.iwork.keynote.key" then return "Bundle Package Keynote" else return false end if end retKeynoteBundleOrNot on getUTIfromPath(anAlias) set aPOSIXpath to POSIX path of anAlias set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath if aURL = missing value then return "" set aRes to aURL’s resourceValuesForKeys:{current application’s NSURLTypeIdentifierKey} |error|:(missing value) if aRes = missing value then return "" return (aRes’s NSURLTypeIdentifierKey) as string end getUTIfromPath |
More from my site
(Visited 49 times, 1 visits today)