12/10 Skimで、現在表示中のページを別ファイルにPDF形式で書き出す
オープンソースのPDFビューワー「Skim」で、現在表示中のPDFのページを別のPDFに書き出すAppleScriptです。
最初は、現在表示中のページだけを残して、他のページを「削除する」AppleScriptを書いていたのですが、Skimではpageを削除できないことにあとから気付きました。
そこで、急遽「ページごとに別ファイルに書き出す」Scriptを機能ダウンさせて現在のページのみPDFで別ファイルに書き出すように変更。
| スクリプト名:Skimで、現在表示中のページを別ファイルにPDF形式で書き出す |
| tell application “Skim” tell document 1 set aBounds to selection bounds tell current page set grabData to grab for aBounds as PDF end tell end tell end tell set newAlias to choose file name write_to_file(grabData, newAlias, false) of me –ファイルの追記ルーチン「write_to_file」 –追記データ、追記対象ファイル、boolean(trueで追記) on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as text set the open_target_file to open for access file target_file with write permission if append_data is false then set eof of the open_target_file to 0 write this_data to the open_target_file starting at eof close access the open_target_file return true on error error_message try close access file target_file end try return error_message end try end write_to_file |
こちらが、動かないほうのバージョンです。コンパイル(構文確認)も通るのですが、アプリケーション側がサポートしていないオブジェクトとコマンドの組み合わせだと動かないという、いい見本です。
| スクリプト名:Skimで、現在表示中のページ以外をすべて削除する(ダメ) |
| –そもそも、pageをdeleteすることができなかった –→ 現在のページだけをExportする方向で書き直し tell application “Skim” tell document 1 set curP to index of current page –現在表示中のページ番号(index)を取得 set totalP to count every page –全ページ数を取得 if totalP = 1 then display dialog “1ページしか存在しない書類は処理対象外です” buttons {“OK”} default button 1 with icon 1 return end if if curP = 1 then –現在表示中のページが1ページ目だった場合の処理 delete (pages 2 thru -1) else if curP = totalP then –現在表示中のページが最終ページだった場合の処理 delete (pages 1 thru -2) else –その他 通常処理 delete (pages 1 thru (curP - 1)) delete (pages (curP + 1) thru -1) end if end tell end tell |











