指定ファイルからのメタデータ情報の取得を行うAppleScriptです。
メタデータの取得はshell commandの「mdls」で行えます。ほぼそれと同じ内容です。ループですぺての属性値を取得するか、属性ラベルを指定して個別に属性値を取り出すことになります。
この方法でメタデータの書き込みや追記が行えないかと調べてみましたが、どうもできないようで「自前でMDImporterを作れ」とか言われてもテーマが大きすぎて困ります……
メタデータの書き込みはshell commandのほうが手っ取り早そうです。
AppleScript名:ファイルからのメタデータ情報の取得 v1scptd |
— – Created by: Takaaki Naganoya – Created on: 2019/11/21 — – Copyright © 2019 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions property |NSURL| : a reference to current application’s |NSURL| property NSMetadataItem : a reference to current application’s NSMetadataItem set aFile to POSIX path of (choose file) set aURL to |NSURL|’s fileURLWithPath:aFile set aMetaInfo to NSMetadataItem’s alloc()’s initWithURL:aURL set attrList to (aMetaInfo’s attributes()) as list set metaList to {} repeat with i in attrList set j to contents of i set aTmpVal to (aMetaInfo’s valueForAttribute:(j)) set the end of metaList to {j as string, aTmpVal as {number, string, date, list}} end repeat return metaList |
AppleScript名:ファイルからのメタデータ情報の取得 v2a.scptd |
— – Created by: Takaaki Naganoya – Created on: 2019/11/21 — – Copyright © 2019 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions property |NSURL| : a reference to current application’s |NSURL| property NSMetadataItem : a reference to current application’s NSMetadataItem set aFile to POSIX path of (choose file) set aURL to |NSURL|’s fileURLWithPath:aFile set aMetaInfo to NSMetadataItem’s alloc()’s initWithURL:aURL –fixed –指定した属性ラベルの値だけ一括で取り出す set metaDict to (aMetaInfo’s valuesForAttributes:{"kMDItemContentTypeTree", "kMDItemContentType"}) as record –> (* (NSDictionary) { kMDItemContentTypeTree:{ "com.apple.application-bundle", "com.apple.localizable-name-bundle", "com.apple.application-bundle", "public.directory", "public.executable", "com.apple.application", "public.item", "com.apple.package", "com.apple.bundle" }, kMDItemContentType:"com.apple.application-bundle" } *) |
More from my site
(Visited 355 times, 3 visits today)