SSブログ

PDFの必要な情報を取得する [AppleScript辞書はつくれるか?]

いくつもあるPDFの、とある情報が素早く見たかったのでスクリプトを作ってみました。


アプリケーション形式と変換形式の2つがほしかったのです。


ss2.jpg

シェルスクリプトの mdls を使って調べると… 

ss1.jpg

そこから必要な部分を抜き出す処理をしてみる。

(* 選択されたファイルを使用する場合 *)

tell application "Finder"

set selectionItem to selection

end tell

repeat with logationUrl in selectionItem

set logationUrl to logationUrl as text

set ans to my thekMDItemCreator(logationUrl)

display dialog ans

end repeat

 

(* ドロプレット部分 *)

on open dropItem

repeat with logationUrl in dropItem

set ans to my thekMDItemCreator(logationUrl)

display dialog ans

end repeat

end open

 

(* 情報取得部分 *)

on thekMDItemCreator(logationUrl)

--| 適切なPOSIXパステキストを取得 |

set logationUrl to logationUrl as text

if logationUrl contains ":" then set logationUrl to POSIX path of logationUrl

--| 情報の取得と処理 |

set aName to "File" & return & "   " & (text 39 thru -2 of (do shell script ("mdls \"" & logationUrl & "\" | grep 'kMDItemFSName'")))

try

set ans1 to "使用アプリケーション:" & return & "   " & (text 39 thru -2 of (do shell script ("mdls \"" & logationUrl & "\" | grep 'kMDItemCreator'")))

set ans2 to "PDF変換:" & return & "   " & (text 6 thru -2 of (do shell script ("mdls \"" & logationUrl & "\" | grep -A1 'kMDItemEncodingApplications' | tail -n 1")))

set ans to aName & return & ans1 & return & ans2

on error

--| 未対応のファイルだった場合の処理 |

set ans to aName & return & return & " は未対応のファイルです"

end try

return ans

end thekMDItemCreator

 

ss4.jpg

(これそのものが必要になる人はまあいないでしょうが…)


nice!(1)  コメント(0) 
共通テーマ:パソコン・インターネット

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。