PDFOutline

[PDFKit]PDF選択ページを残して他のページを削除(別名保存)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use framework "UniformTypeIdentifiers"
010use framework "PDFKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017#############################
018###ダイアログを前面に出す
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025############ デフォルトロケーション
026set appFileManager to refMe's NSFileManager's defaultManager()
027set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
028set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
029set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
030#
031set listUTI to {"com.adobe.pdf"}
032set strMes to ("【A】PDFファイルを選んでください") as text
033set strPrompt to ("【A】PDFファイルを選んでください") as text
034try
035  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
036on error
037  log "エラーしました"
038  return "エラーしました"
039end try
040##パス
041set strFilePath to (POSIX path of aliasFilePath) as text
042set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
043set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
044set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
045set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
046set ocidFileName to ocidBaseFilePathURL's lastPathComponent()
047##読み込み
048#NSDATA
049set ocidOption to (refMe's NSDataReadingMappedIfSafe)
050set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
051if (item 2 of listResponse) = (missing value) then
052  set ocidReadData to (item 1 of listResponse)
053else if (item 2 of listResponse) ≠ (missing value) then
054  set strErrorNO to (item 2 of listResponse)'s code() as text
055  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
056  refMe's NSLog("■:" & strErrorNO & strErrorMes)
057  return "エラーしました" & strErrorNO & strErrorMes
058end if
059#PDFDOC
060set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithData:(ocidReadData)
061set numCntPDFPage to ocidActivDoc's pageCount()
062#Array
063set ocidPageNoArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
064repeat with itemPageNo from 1 to (numCntPDFPage) by 1
065  (ocidPageNoArrayM's addObject:(itemPageNo))
066end repeat
067#ダイアログ
068set listChoosePageNo to ocidPageNoArrayM as list
069set strName to (name of current application) as text
070if strName is "osascript" then
071  tell application "Finder" to activate
072else
073  tell current application to activate
074end if
075set strTitle to "選んでください" as text
076set strPrompt to "取り出すページ番号を選んでください" as text
077try
078  set listResponse to (choose from list listChoosePageNo with title strTitle with prompt strPrompt default items (item 1 of listChoosePageNo) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
079on error
080  log "エラーしました"
081  return "エラーしました"
082  error "エラーしました" number -200
083end try
084if listResponse = {} then
085  log "何も選択していない"
086  return
087else if (item 1 of listResponse) is false then
088  return "キャンセルしました"
089  error "キャンセルしました" number -200
090end if
091log listResponse
092(*
093PDFにはPDFDocumentとそれの下位にPDFPageがある
094注釈はPDFPage
095メタデータやBookMarkはPDFDocumentに属しているので
096それぞれ処理が必要
097ここでは
098PDFDocumentを複製して不要なページを削除する手法を使う
099ユーザーが選んだページ以外を削除する処理になる
100*)
101#ページを削除する事になるので後ろのページから処理
102repeat with itemPageNo from numCntPDFPage to 1 by -1
103  if listResponse contains itemPageNo then
104    log "マッチ: " & itemPageNo
105  else
106    (ocidActivDoc's removePageAtIndex:(itemPageNo - 1))
107  end if
108end repeat
109
110##bookmarkはROOTは残してリセット
111set ocidOutLineRoot to ocidActivDoc's outlineRoot()
112if ocidOutLineRoot ≠ (missing value) then
113  set numChild to ocidOutLineRoot's numberOfChildren() as integer
114  repeat with itemChildNo from (numChild - 1) to 0 by -1
115    set ocidChild to (ocidOutLineRoot's childAtIndex:(itemChildNo))
116    ocidChild's removeFromParent()
117  end repeat
118end if
119
120#保存先パス
121set strSaveExtension to ("") as text
122repeat with itemPageNo in listResponse
123  set strSaveExtension to (strSaveExtension & itemPageNo & ".") as text
124end repeat
125set strSaveExtension to (strSaveExtension & "pdf") as text
126set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:(strSaveExtension)
127#保存オプション
128set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
129ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentOwnerPasswordOption)
130ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentUserPasswordOption)
131ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentAccessPermissionsOption)
132ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentBurnInAnnotationsOption)
133ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentOptimizeImagesForScreenOption)
134ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentSaveImagesAsJPEGOption)
135ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentSaveTextFromOCROption)
136#保存
137set boolDone to ocidActivDoc's writeToURL:(ocidSaveFilePathURL) withOptions:(ocidOptionDict)
138
139return boolDone
AppleScriptで生成しました

|

[PDFkit]しおり(BOOKMARK)の一覧取得(Acrobat不要タイプ)途中

ダウンロード - 20240504_071151.html


あくまでも参考にしてください

【スクリプトエディタで開く】 |

サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# Acrobat不要
005# しおり(ブックマーク)一覧出力
006#
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.6"
010use framework "Foundation"
011use framework "AppKit"
012use framework "PDFKit"
013use scripting additions
014
015property refMe : a reference to current application
016
017property numCntBkm : 0 as integer
018property ocidActivDoc : (missing value)
019
020set appFileManager to refMe's NSFileManager's defaultManager()
021
022##################################
023####ドキュメントを開いているか?チェック
024##################################
025
026###ダイアログを前面に出す
027tell current application
028  set strName to name as text
029end tell
030####スクリプトメニューから実行したら
031if strName is "osascript" then
032  tell application "Finder"
033    activate
034  end tell
035else
036  tell current application
037    activate
038  end tell
039end if
040##################
041###ダイアログ
042##################
043set listUTI to {"com.adobe.pdf"}
044set aliasDefaultLocation to (path to desktop folder from user domain) as alias
045####ダイアログを出す
046set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
047
048##################
049### パス
050##################
051set strFilePath to POSIX path of aliasFilePath as text
052set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
053set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
054set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
055set strFileName to (ocidFilePathURL's lastPathComponent()) as text
056##################
057### 出力用ファイル
058##################
059##パスはPDFファイル名+拡張子txt
060set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
061set strSaveFileName to (strFileName & ".しおり.tsv") as text
062set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
063##保存するテキスト
064set ocidOutPutText to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
065ocidOutPutText's appendString:("\n")
066##################
067### 本処理
068##################
069###PDF読み込み
070set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL)
071##################
072### メタデータ
073##################
074#####アトリビュートを取得して
075set ocidAttributes to ocidActivDoc's documentAttributes()
076#キーをリストで取得して
077set ocidAllKeysArray to ocidAttributes's allKeys()
078repeat with itemKeysArray in ocidAllKeysArray
079  #
080  set strGetKey to (itemKeysArray) as text
081  set ocidValue to (ocidAttributes's valueForKey:(strGetKey))
082  ###日付の場合
083  if strGetKey contains "Date" then
084    set ocidValue to doGetDateNo({"GGyy年MM月dd日EEEE", 2})
085    ###キーワードの場合
086  else if strGetKey contains "Keywords" then
087    set strKeyWord to ("") as text
088    repeat with itemValuet in ocidValue
089      ##カンマで区切りたい場合は\tを,に変更
090      set ocidKeyWord to (itemValuet's stringByReplacingOccurrencesOfString:("\n") withString:("\t"))
091      set strKeyWord to (strKeyWord & ocidKeyWord) as text
092    end repeat
093    set ocidValue to (strKeyWord) as text
094  end if
095  if ocidValue = (missing value) then
096    set ocidValue to ("未設定") as text
097  end if
098  set strSetValue to (strGetKey & " : " & ocidValue & "\n") as text
099  (ocidOutPutText's appendString:(strSetValue))
100end repeat
101
102(ocidOutPutText's appendString:("\n"))
103
104##################
105### シオリの処理
106##################
107(ocidOutPutText's appendString:("しおり outline boookmark\n"))
108###しおりのROOTを取得
109set ocidOutLineRoot to ocidActivDoc's outlineRoot()
110set ocidSetValue to ocidOutLineRoot's label
111(ocidOutPutText's appendString:("Root: " & ocidSetValue & "\n"))
112###無い場合は終了
113if ocidOutLineRoot = missing value then
114  return "しおり outline boookmarkが見つかりませんでした"
115end if
116set numChild to ocidOutLineRoot's numberOfChildren() as integer
117(ocidOutPutText's appendString:("ROOTの子要素数: " & numChild & "\n"))
118(ocidOutPutText's appendString:("Book Mark Root\tLabel\tIndex\tLinkPage\tLinkPoint\n"))
119##########################
120##ROOT
121repeat with itemFirstChildNo from 0 to (numChild - 1) by 1
122  ##ROOTの1階層子要素
123  set ocidFirstChild to (ocidOutLineRoot's childAtIndex:(itemFirstChildNo))
124  ##ラベル
125  set strChildLabel to (ocidFirstChild's label) as text
126  ##インデックス
127  set strChildIndex to (ocidFirstChild's |index|) as text
128  ##移動先
129  set ocidDistination to (ocidFirstChild's destination)
130  set ocidPDFPage to ocidDistination's page
131  ##リンク先
132  set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
133  set intLinkPageNO to (numLinkPageNO - 1) as integer
134  ##ポイント(リンク先の座標)も必要な場合はpointも処理する
135  set recordDistPoint to ocidDistination's |point| as record
136  #
137  set numCntBkm to (numCntBkm + 1) as integer
138  set strLineNO to doGetLineNo(numCntBkm)
139  (ocidOutPutText's appendString:(strLineNO))
140  (ocidOutPutText's appendString:("\t" & strChildLabel))
141  (ocidOutPutText's appendString:("\t" & strChildIndex))
142  (ocidOutPutText's appendString:("\t" & intLinkPageNO))
143  
144  (ocidOutPutText's appendString:("\tx:" & (x of recordDistPoint) & ",y:" & (y of recordDistPoint) & "\n"))
145  ###2階層目の子要素の有無
146  set numSecondChild to ocidFirstChild's numberOfChildren() as integer
147  if numSecondChild = 0 then
148    log "子要素無"
149  else
150    log "子要素有"
151    set ocidSaveString to doGetChild({ocidFirstChild, ocidOutPutText, itemFirstChildNo})
152  end if
153  
154end repeat
155
156
157
158##################
159### テキスト保存
160##################
161set listDone to ocidOutPutText's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
162return
163
164
165##################
166### 子要素再帰取得
167##################
168
169to doGetChild({argChildElement, argOutPutText})
170  set numCntChild to argChildElement's numberOfChildren() as integer
171  
172  repeat with itemChildNO from 0 to (numCntChild - 1) by 1
173    set ocidSubElement to (argChildElement's childAtIndex:(itemChildNO))
174    ##ラベル
175    set strChildLabel to (ocidSubElement's label) as text
176    ##インデックス
177    set strChildIndex to (ocidSubElement's |index|) as text
178    ##移動先
179    set ocidDistination to (ocidSubElement's destination)
180    set ocidPDFPage to ocidDistination's page
181    ##リンク先
182    set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
183    set intLinkPageNO to (numLinkPageNO - 1) as integer
184    ##ポイント(リンク先の座標)も必要な場合はpointも処理する
185    set recordDistPoint to ocidDistination's |point| as record
186    #
187    set numCntBkm to (numCntBkm + 1) as integer
188    set strLineNO to doGetLineNo(numCntBkm)
189    (argOutPutText's appendString:(strLineNO))
190    (argOutPutText's appendString:("\t" & strChildLabel))
191    (argOutPutText's appendString:("\t" & strChildIndex))
192    (argOutPutText's appendString:("\t" & intLinkPageNO))
193    (argOutPutText's appendString:("\tx:" & (x of recordDistPoint) & ",y:" & (y of recordDistPoint) & "\n"))
194    ###さらに子要素ある場合
195    set numSecondChild to ocidSubElement's numberOfChildren() as integer
196    if numSecondChild = 0 then
197      log "子要素無"
198    else
199      log "子要素有"
200      doGetChild({ocidSubElement, argOutPutText})
201    end if
202    
203  end repeat
204  return argOutPutText
205end doGetChild
206
207
208
209
210
211################################
212# ゼロパディング
213################################
214to doGetLineNo(argLineNo)
215  set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
216  (ocidFormatter's setMinimumIntegerDigits:(3))
217  (ocidFormatter's setMaximumIntegerDigits:(3))
218  set ocidDecStr to (ocidFormatter's stringFromNumber:(argLineNo))
219  return ocidDecStr
220end doGetLineNo
221
222################################
223# BOOKMARK必要項目の取得
224################################
225to doGetBookMark(argBoookmarkChild)
226  
227  ##ラベル
228  set strFirstChildLabel to (argBoookmarkChild's label) as text
229  ##インデックス
230  set strFirstChildIndex to (argBoookmarkChild's |index|) as text
231  ##移動先
232  set ocidDistination to (argBoookmarkChild's destination)
233  set ocidPDFPage to ocidDistination's page
234  ##リンク先
235  set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
236  set intLinkPageNO to (numLinkPageNO - 1) as integer
237  ##ポイント(リンク先の座標)も必要な場合はpointも処理する
238  set listDistPoint to ocidDistination's |point| as list
239  
240  
241end doGetBookMark
242
243
244################################
245# 和暦ゼロパディング
246################################
247# 日付 doGetDateNo(argDateFormat,argCalendarNO)
248# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
249# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
250################################
251to doGetDateNo({argDateFormat, argCalendarNO})
252  ##渡された値をテキストで確定させて
253  set strDateFormat to argDateFormat as text
254  set intCalendarNO to argCalendarNO as integer
255  ###日付情報の取得
256  set ocidDate to current application's NSDate's |date|()
257  ###日付のフォーマットを定義(日本語)
258  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
259  ###和暦 西暦 カレンダー分岐
260  if intCalendarNO = 1 then
261    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
262  else if intCalendarNO = 2 then
263    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
264  else
265    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
266  end if
267  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
268  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
269  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
270  ###設定
271  ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
272  ocidFormatterJP's setLocale:(ocidLocaleJP)
273  ocidFormatterJP's setCalendar:(ocidCalendarJP)
274  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
275  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
276  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
277  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
278  ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
279  ###渡された値でフォーマット定義
280  ocidFormatterJP's setDateFormat:(strDateFormat)
281  ###フォーマット適応
282  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
283  ###テキストで戻す
284  set strDateAndTime to ocidDateAndTime as text
285  return strDateAndTime
286end doGetDateNo
AppleScriptで生成しました

|

[PDFkit]bookmark しおりの取得 (3階層目まで 途中)


あくまでも参考にしてください

【スクリプトエディタで開く】 |

サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# ブックマークを3階層まで取得テキストにする
005#
006#
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.6"
010use framework "Foundation"
011use framework "AppKit"
012use framework "PDFKit"
013use scripting additions
014
015
016property refMe : a reference to current application
017
018set appFileManager to refMe's NSFileManager's defaultManager()
019
020##################################
021####ドキュメントを開いているか?チェック
022##################################
023
024###ダイアログを前面に出す
025tell current application
026  set strName to name as text
027end tell
028####スクリプトメニューから実行したら
029if strName is "osascript" then
030  tell application "Finder"
031    activate
032  end tell
033else
034  tell current application
035    activate
036  end tell
037end if
038##################
039###ダイアログ
040##################
041set listUTI to {"com.adobe.pdf"}
042set aliasDefaultLocation to (path to desktop folder from user domain) as alias
043####ダイアログを出す
044set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
045
046##################
047### パス
048##################
049set strFilePath to POSIX path of aliasFilePath as text
050set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
051set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
052set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
053set strFileName to (ocidFilePathURL's lastPathComponent()) as text
054##################
055### 出力用ファイル
056##################
057##パスはPDFファイル名+拡張子txt
058set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
059set strSaveFileName to (strFileName & ".しおり.txt") as text
060set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
061##保存するテキスト
062set ocidOutPutText to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
063ocidOutPutText's appendString:("\n")
064##################
065### 本処理
066##################
067###PDF読み込み
068set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL)
069##################
070### メタデータ
071##################
072#####アトリビュートを取得して
073set ocidAttributes to ocidActivDoc's documentAttributes()
074#キーをリストで取得して
075set ocidAllKeysArray to ocidAttributes's allKeys()
076repeat with itemKeysArray in ocidAllKeysArray
077  #
078  set strGetKey to (itemKeysArray) as text
079  set ocidValue to (ocidAttributes's valueForKey:(strGetKey))
080  ###日付の場合
081  if strGetKey contains "Date" then
082    set ocidValue to doGetDateNo({"GGyy年MM月dd日EEEE", 2})
083    ###キーワードの場合
084  else if strGetKey contains "Keywords" then
085    set strKeyWord to ("") as text
086    repeat with itemValuet in ocidValue
087      ##カンマで区切りたい場合は\tを,に変更
088      set ocidKeyWord to (itemValuet's stringByReplacingOccurrencesOfString:("\n") withString:("\t"))
089      set strKeyWord to (strKeyWord & ocidKeyWord) as text
090    end repeat
091    set ocidValue to (strKeyWord) as text
092  end if
093  if ocidValue = (missing value) then
094    set ocidValue to ("未設定") as text
095  end if
096  set strSetValue to (strGetKey & " : " & ocidValue & "\n") as text
097  (ocidOutPutText's appendString:(strSetValue))
098end repeat
099
100(ocidOutPutText's appendString:("\n"))
101
102##################
103### シオリの処理
104##################
105(ocidOutPutText's appendString:("しおり outline boookmark\n"))
106###しおりのROOTを取得
107set ocidOutLineRoot to ocidActivDoc's outlineRoot()
108set ocidSetValue to ocidOutLineRoot's label
109(ocidOutPutText's appendString:("Root: " & ocidSetValue & "\n"))
110###無い場合は終了
111if ocidOutLineRoot = missing value then
112  return "しおり outline boookmarkが見つかりませんでした"
113end if
114set numChild to ocidOutLineRoot's numberOfChildren() as integer
115(ocidOutPutText's appendString:("ROOTの子要素数: " & numChild & "\n"))
116(ocidOutPutText's appendString:("Book Mark Root\tLabel\tIndex\tLinkPage\tLinkPoint\n"))
117##########################
118repeat with itemFirstChildNo from 0 to (numChild - 1) by 1
119  ##ROOTの1階層子要素
120  set ocidFirstChild to (ocidOutLineRoot's childAtIndex:(itemFirstChildNo))
121  ###2階層目の子要素の有無
122  set numSecondChild to ocidFirstChild's numberOfChildren() as integer
123  ##ラベル
124  set strChildLabel to (ocidFirstChild's label) as text
125  ##インデックス
126  set strChildIndex to (ocidFirstChild's |index|) as text
127  ##移動先
128  set ocidDistination to (ocidFirstChild's destination)
129  set ocidPDFPage to ocidDistination's page
130  ##リンク先
131  set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
132  set intLinkPageNO to (numLinkPageNO - 1) as integer
133  ##ポイント(リンク先の座標)も必要な場合はpointも処理する
134  set recordDistPoint to ocidDistination's |point| as record
135  #
136  (ocidOutPutText's appendString:("\tChild: " & itemFirstChildNo & ""))
137  (ocidOutPutText's appendString:("\t" & strChildLabel))
138  (ocidOutPutText's appendString:("\t" & strChildIndex))
139  (ocidOutPutText's appendString:("\t" & intLinkPageNO))
140  (ocidOutPutText's appendString:("\tx:" & (x of recordDistPoint) & ",y:" & (y of recordDistPoint) & "\n"))
141  if numSecondChild > 0 then
142    ##################2
143    repeat with itemSecondChildNo from 0 to (numSecondChild - 1) by 1
144      #2階層目の子要素
145      set ocidSecondChild to (ocidFirstChild's childAtIndex:(itemSecondChildNo))
146      ###3階層目の子要素の有無
147      set numThirdChild to ocidSecondChild's numberOfChildren() as integer
148      ##ラベル
149      set strChildLabel to (ocidSecondChild's label) as text
150      ##インデックス
151      set strChildIndex to (ocidSecondChild's |index|) as text
152      ##移動先
153      set ocidDistination to (ocidSecondChild's destination)
154      set ocidPDFPage to ocidDistination's page
155      ##リンク先
156      set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
157      set intLinkPageNO to (numLinkPageNO - 1) as integer
158      ##ポイント(リンク先の座標)も必要な場合はpointも処理する
159      set recordDistPoint to ocidDistination's |point| as record
160      #
161      (ocidOutPutText's appendString:("\t\tChild: " & itemFirstChildNo & "-" & itemSecondChildNo & ""))
162      (ocidOutPutText's appendString:("\t" & strChildLabel))
163      (ocidOutPutText's appendString:("\t" & strChildIndex))
164      (ocidOutPutText's appendString:("\t" & intLinkPageNO))
165      (ocidOutPutText's appendString:("\tx:" & (x of recordDistPoint) & ",y:" & (y of recordDistPoint) & "\n"))
166      
167      if numThirdChild > 0 then
168        repeat with itemThirdChildNo from 0 to (numThirdChild - 1) by 1
169          #3階層目の子要素
170          set ocidThirdChild to (ocidSecondChild's childAtIndex:(itemThirdChildNo))
171          ###4階層目の子要素の有無
172          set numForthChild to ocidThirdChild's numberOfChildren() as integer
173          ##ラベル
174          set strChildLabel to (ocidThirdChild's label) as text
175          ##インデックス
176          set strChildIndex to (ocidThirdChild's |index|) as text
177          ##移動先
178          set ocidDistination to (ocidThirdChild's destination)
179          set ocidPDFPage to ocidDistination's page
180          ##リンク先
181          set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
182          set intLinkPageNO to (numLinkPageNO - 1) as integer
183          ##ポイント(リンク先の座標)も必要な場合はpointも処理する
184          set recordDistPoint to ocidDistination's |point| as record
185          #
186          (ocidOutPutText's appendString:("\t\t\tChild: " & itemFirstChildNo & "-" & itemSecondChildNo & "-" & itemThirdChildNo & ""))
187          (ocidOutPutText's appendString:("\t" & strChildLabel))
188          (ocidOutPutText's appendString:("\t" & strChildIndex))
189          (ocidOutPutText's appendString:("\t" & intLinkPageNO))
190          (ocidOutPutText's appendString:("\tx:" & (x of recordDistPoint) & ",y:" & (y of recordDistPoint) & "\n"))
191          
192          
193        end repeat
194      end if
195    end repeat
196    
197    
198    
199    
200  end if
201end repeat
202
203
204
205
206##################
207### テキスト保存
208##################
209set listDone to ocidOutPutText's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
210return
211
212################################
213# BOOKMARK必要項目の取得
214################################
215to doGetBookMark(argBoookmarkChild)
216  
217  ##ラベル
218  set strFirstChildLabel to (argBoookmarkChild's label) as text
219  ##インデックス
220  set strFirstChildIndex to (argBoookmarkChild's |index|) as text
221  ##移動先
222  set ocidDistination to (argBoookmarkChild's destination)
223  set ocidPDFPage to ocidDistination's page
224  ##リンク先
225  set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
226  set intLinkPageNO to (numLinkPageNO - 1) as integer
227  ##ポイント(リンク先の座標)も必要な場合はpointも処理する
228  set listDistPoint to ocidDistination's |point| as list
229  
230  
231end doGetBookMark
232
233
234################################
235# 和暦ゼロパディング
236################################
237# 日付 doGetDateNo(argDateFormat,argCalendarNO)
238# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
239# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
240################################
241to doGetDateNo({argDateFormat, argCalendarNO})
242  ##渡された値をテキストで確定させて
243  set strDateFormat to argDateFormat as text
244  set intCalendarNO to argCalendarNO as integer
245  ###日付情報の取得
246  set ocidDate to current application's NSDate's |date|()
247  ###日付のフォーマットを定義(日本語)
248  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
249  ###和暦 西暦 カレンダー分岐
250  if intCalendarNO = 1 then
251    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
252  else if intCalendarNO = 2 then
253    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
254  else
255    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
256  end if
257  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
258  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
259  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
260  ###設定
261  ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
262  ocidFormatterJP's setLocale:(ocidLocaleJP)
263  ocidFormatterJP's setCalendar:(ocidCalendarJP)
264  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
265  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
266  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
267  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
268  ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
269  ###渡された値でフォーマット定義
270  ocidFormatterJP's setDateFormat:(strDateFormat)
271  ###フォーマット適応
272  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
273  ###テキストで戻す
274  set strDateAndTime to ocidDateAndTime as text
275  return strDateAndTime
276end doGetDateNo
AppleScriptで生成しました

|

[PDFoutline]しおり boookmarkをテキストに保存


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "AppKit"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##################################
####ドキュメントを開いているか?チェック
##################################

###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
##################
###ダイアログ
##################
set listUTI to {"com.adobe.pdf"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

##################
### パス
##################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
set strFileName to (ocidFilePathURL's lastPathComponent()) as text
##################
### 出力用ファイル
##################
##パスはPDFファイル名+拡張子txt
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set strSaveFileName to (strFileName & ".しおり.txt") as text
set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
##保存するテキスト
set ocidOutPutText to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidOutPutText's appendString:("\n")
##################
### 本処理
##################
###PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL)
##################
### メタデータ
##################
#####アトリビュートを取得して
set ocidAttributes to ocidActivDoc's documentAttributes()
#キーをリストで取得して
set ocidAllKeysArray to ocidAttributes's allKeys()
repeat with itemKeysArray in ocidAllKeysArray
  #
  set strGetKey to (itemKeysArray) as text
  set ocidValue to (ocidAttributes's valueForKey:(strGetKey))
  ###日付の場合
  if strGetKey contains "Date" then
    set ocidValue to doGetDateNo({"GGyy年MM月dd日EEEE", 2})
    ###キーワードの場合
  else if strGetKey contains "Keywords" then
    set strKeyWord to ("") as text
    repeat with itemValuet in ocidValue
      ##カンマで区切りたい場合は\tを,に変更
      set ocidKeyWord to (itemValuet's stringByReplacingOccurrencesOfString:("\n") withString:("\t"))
      set strKeyWord to (strKeyWord & ocidKeyWord) as text
    end repeat
    set ocidValue to (strKeyWord) as text
  end if
  if ocidValue = (missing value) then
    set ocidValue to ("未設定") as text
  end if
  set strSetValue to (strGetKey & " : " & ocidValue & "\n") as text
(ocidOutPutText's appendString:(strSetValue))
end repeat

(ocidOutPutText's appendString:("\n"))

##################
### シオリの処理
##################
(ocidOutPutText's appendString:("しおり outline boookmark\n"))
###しおりのROOTを取得
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
set ocidSetValue to ocidOutLineRoot's label
(ocidOutPutText's appendString:("Root: " & ocidSetValue & "\n"))
###無い場合は終了
if ocidOutLineRoot = missing value then
return "しおり outline boookmarkが見つかりませんでした"
end if
set numChild to ocidOutLineRoot's numberOfChildren() as integer
##
repeat with itemNumChildNo from 0 to (numChild - 1) by 1
  ##ROOTの1階層子要素
  set ocidFirstChild to (ocidOutLineRoot's childAtIndex:(itemNumChildNo))
  ##ラベル
  set strFirstChildLabel to (ocidFirstChild's label) as text
  ##インデックス
  set strFirstChildIndex to (ocidFirstChild's |index|) as text
  ##移動先
  set ocidDistination to (ocidFirstChild's destination)
  set ocidPDFPage to ocidDistination's page
  ##リンク先
  set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
  set numLinkPageNO to (numLinkPageNO + 1) as integer
  ##ポイント(リンク先の座標)も必要な場合はpointも処理する
  ## log ocidDistination's |point| as list
  ##テキストに保存
  set strSetVale to ("Index:" & strFirstChildIndex & "\t" & "Destination: " & numLinkPageNO & "\t" & strFirstChildLabel)
(ocidOutPutText's appendString:(strSetVale & "\n"))
  ###2階層目の子要素の有無
  set numSubChild to ocidFirstChild's numberOfChildren() as integer
  if numSubChild > 0 then
    repeat with itemNumSubChildNo from 0 to (numSubChild - 1) by 1
      ###2階層目の子要素
      set ocidSubChild to (ocidFirstChild's childAtIndex:(itemNumSubChildNo))
      ##ラベル
      set strSubChildLabel to (ocidSubChild's label) as text
      ##インデックス
      set strSubChildIndex to (ocidSubChild's |index|) as text
      ##移動先
      set ocidDistination to (ocidSubChild's destination)
      set ocidPDFPage to ocidDistination's page
      ##リンク先
      set numLinkPageNO to (ocidActivDoc's indexForPage:(ocidPDFPage))
      set numLinkPageNO to (numLinkPageNO + 1) as integer
      ##テキスト出力
      set strSetSubVale to ("Index:" & strSubChildIndex & "\t" & "Destination: " & numLinkPageNO & "\t " & strSubChildLabel)
(ocidOutPutText's appendString:("\t " & strSetSubVale & "\n"))
    end repeat
  else if numSubChild = 0 then
log "子要素終わり"
    exit repeat
  end if
  
  
end repeat

##################
### テキスト保存
##################
set listDone to ocidOutPutText's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
return





################################
# 和暦ゼロパディング
################################
################################
# 日付 doGetDateNo(argDateFormat,argCalendarNO)
# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
################################
to doGetDateNo({argDateFormat, argCalendarNO})
  ##渡された値をテキストで確定させて
  set strDateFormat to argDateFormat as text
  set intCalendarNO to argCalendarNO as integer
  ###日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義(日本語)
  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
  ###和暦 西暦 カレンダー分岐
  if intCalendarNO = 1 then
    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
  else if intCalendarNO = 2 then
    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
  else
    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
  end if
  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
  ###設定
ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
ocidFormatterJP's setLocale:(ocidLocaleJP)
ocidFormatterJP's setCalendar:(ocidCalendarJP)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
  ###渡された値でフォーマット定義
ocidFormatterJP's setDateFormat:(strDateFormat)
  ###フォーマット適応
  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate)
  ###テキストで戻す
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

[PDFOutline]親要素に対して子要素を全部入れる

現時点でプレビューでの表示が期待値にならない…トホホ
Screencapture-20230401-140751


【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##################
###ダイアログ
##################
set listUTI to {"com.adobe.pdf"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias


##################
### パス
##################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)

##################
### 本処理
##################
###PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL
###ページ数取得
set numCntPage to ocidActivDoc's pageCount() as integer
###しおりのROOTを取得
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
###無い場合は作る
if ocidOutLineRoot = missing value then
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
else
  ####ある場合は初期化する
  ocidOutLineRoot's removeFromParent()
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
end if
########################################
####親要素
########################################
###アウトライン初期化
set ocidOutLineParent to refMe's PDFOutline's alloc()'s init()
###ラベルの初期化
set strLabel to ("ページ目次") as text
set ocidLabel to (refMe's NSString's stringWithString:strLabel)
###ラベルをセット
ocidOutLineParent's setLabel:ocidLabel
###対象のドキュメントを指定
ocidOutLineParent's setDocument:ocidActivDoc
###ROOTに子要素として入れる
ocidOutLineRoot's insertChild:ocidOutLineParent atIndex:0

###カウンター初期化
set numChkPageNo to 1 as integer
set numChkPageNoJs to 0 as integer
##################
### ページ数繰り返し
##################
repeat numCntPage times
  set ocidSetPage to ocidActivDoc's pageAtIndex:numChkPageNoJs
  ########################################
  #### 子要素
  ########################################
  ###アウトライン初期化
  set ocidOutLineChild to refMe's PDFOutline's alloc()'s init()
  ###ページサイズを取得
  set ocidPageBounds to ocidSetPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox)
  set listPageSize to item 2 of ocidPageBounds as list
  set numW to item 1 of listPageSize as number
  set numH to item 2 of listPageSize as number
  #### Destinationをセット↑ここで求めた値をそのままページ上部
  set ocidPoint to refMe's NSMakePoint(numW, numH)
  set ocidSetDestination to refMe's PDFDestination's alloc()'s initWithPage:ocidSetPage atPoint:ocidPoint
  ###zoom値はお好みで
  ocidSetDestination's setZoom:0.5
  ####ActionDestinationをセット
  set ocidSetAction to refMe's PDFActionGoTo's alloc()'s initWithDestination:ocidSetDestination
  ###ラベルの初期化
  set strLabel to ("ページ:" & numChkPageNo) as text
  set ocidLabel to (refMe's NSString's stringWithString:strLabel)
  ###ラベルをセット
  ocidOutLineChild's setLabel:ocidLabel
  ###アクションをセット
  ocidOutLineChild's setAction:ocidSetAction
  ###対象のドキュメントを指定
  ocidOutLineChild's setDocument:ocidActivDoc
  ###親要素に対して子要素として入れる
  ocidOutLineParent's insertChild:ocidOutLineChild atIndex:numChkPageNoJs
  ####カウントアップ
  set numChkPageNoJs to numChkPageNoJs + 1 as integer
  set numChkPageNo to numChkPageNo + 1 as integer
end repeat
####保存
(ocidActivDoc's writeToURL:ocidFilePathURL)


return

|

[PDFOutline]親要素に対して子要素として入れる

Screencapture-20230401-133135


【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##################
###ダイアログ
##################
set listUTI to {"com.adobe.pdf"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias


##################
### パス
##################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)

##################
### 本処理
##################
###PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL
###ページ数取得
set numCntPage to ocidActivDoc's pageCount() as integer
###しおりのROOTを取得
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
###無い場合は作る
if ocidOutLineRoot = missing value then
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
else
  ####ある場合は初期化する
  ocidOutLineRoot's removeFromParent()
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
end if

###カウンター初期化
set numChkPageNo to 1 as integer
set numChkPageNoJs to 0 as integer
##################
### ページ数繰り返し
##################
repeat numCntPage times
  ###アウトライン初期化
  set ocidOutLineParent to refMe's PDFOutline's alloc()'s init()
  ###ページ
  set ocidSetPage to ocidActivDoc's pageAtIndex:numChkPageNoJs
  ###ページサイズを取得
  set ocidPageBounds to ocidSetPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox)
  set listPageSize to item 2 of ocidPageBounds as list
  set numW to item 1 of listPageSize as number
  set numH to item 2 of listPageSize as number
  #### Destinationをセット↑ここで求めた値をそのままページ上部
  set ocidPoint to refMe's NSMakePoint(numW, numH)
  set ocidSetDestination to refMe's PDFDestination's alloc()'s initWithPage:ocidSetPage atPoint:ocidPoint
  ###zoom値はお好みで
  ocidSetDestination's setZoom:0.5
  ####ActionDestinationをセット
  set ocidSetAction to refMe's PDFActionGoTo's alloc()'s initWithDestination:ocidSetDestination
  ###ラベルの初期化
  set strLabel to ("ページ:" & numChkPageNo) as text
  set ocidLabel to (refMe's NSString's stringWithString:strLabel)
  ###ラベルをセット
  ocidOutLineParent's setLabel:ocidLabel
  ###アクションをセット
  ocidOutLineParent's setAction:ocidSetAction
  ###対象のドキュメントを指定
  ocidOutLineParent's setDocument:ocidActivDoc
  ###ROOTに子要素として入れる
  ocidOutLineRoot's insertChild:ocidOutLineParent atIndex:numChkPageNoJs
  ###############################################
  ###アウトライン初期化
  set ocidOutLineChild to refMe's PDFOutline's alloc()'s init()
  ###ページサイズを取得
  set ocidPageBounds to ocidSetPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox)
  set listPageSize to item 2 of ocidPageBounds as list
  set numW to item 1 of listPageSize as number
  set numH to item 2 of listPageSize as number
  log
  #### Destinationをセット↑ここで求めた値をそのままページ上部
  set ocidPoint to refMe's NSMakePoint(numW, numH)
  ###zoom値はお好みで
  ocidSetDestination's setZoom:0.5
  ####ActionDestinationをセット
  set ocidSetAction to refMe's PDFActionGoTo's alloc()'s initWithDestination:ocidSetDestination
  ###ラベルの初期化
  set strLabel to ("ページトップ") as text
  set ocidLabel to (refMe's NSString's stringWithString:strLabel)
  ###ラベルをセット
  ocidOutLineChild's setLabel:ocidLabel
  ###アクションをセット
  ocidOutLineChild's setAction:ocidSetAction
  ###対象のドキュメントを指定
  ocidOutLineChild's setDocument:ocidActivDoc
  ###親要素を指定
  ###親要素に対して子要素として入れる
  ocidOutLineParent's insertChild:ocidOutLineChild atIndex:0
  ####カウントアップ
  set numChkPageNoJs to numChkPageNoJs + 1 as integer
  set numChkPageNo to numChkPageNo + 1 as integer
end repeat
####保存
(ocidActivDoc's writeToURL:ocidFilePathURL)


return

|

[PDFOutline]目次の全削除

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##################
###ダイアログ
##################
set listUTI to {"com.adobe.pdf"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

##################
### パス
##################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)

##################
### 本処理
##################
###PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL
###ページ数取得
set numCntPage to ocidActivDoc's pageCount() as integer
###しおりのROOTを取得
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
###無い場合は作る
if ocidOutLineRoot = missing value then
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
else
  ####ある場合は初期化する
  ocidOutLineRoot's removeFromParent()
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
end if
####保存
(ocidActivDoc's writeToURL:ocidFilePathURL)


return

|

[PDFOutline]目次の追加

Screencapture-20230331-171153


【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

##################
###ダイアログ
##################
set listUTI to {"com.adobe.pdf"}
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

##################
### パス
##################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)

##################
### 本処理
##################
###PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL
###ページ数取得
set numCntPage to ocidActivDoc's pageCount() as integer
###しおりのROOTを取得
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
###無い場合は作る
if ocidOutLineRoot = missing value then
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
else
  ####ある場合は初期化する
  ocidOutLineRoot's removeFromParent()
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
end if

###カウンター初期化
set numChkPageNo to 1 as integer
set numChkPageNoJs to 0 as integer
##################
### ページ数繰り返し
##################
repeat numCntPage times
  ###アウトライン初期化
  set ocidOutLineChild to refMe's PDFOutline's alloc()'s init()
  ###ページ
  set ocidSetPage to ocidActivDoc's pageAtIndex:numChkPageNoJs
  ###ページサイズを取得
  set ocidPageBounds to ocidSetPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox)
  set listPageSize to item 2 of ocidPageBounds as list
  set numW to item 1 of listPageSize as number
  set numH to item 2 of listPageSize as number
  #### Destinationをセット↑ここで求めた値をそのままページ上部
  set ocidPoint to refMe's NSMakePoint(numW, numH)
  set ocidSetDestination to refMe's PDFDestination's alloc()'s initWithPage:ocidSetPage atPoint:ocidPoint
  ###zoom値はお好みで
  ocidSetDestination's setZoom:0.5
  ####ActionDestinationをセット
  set ocidSetAction to refMe's PDFActionGoTo's alloc()'s initWithDestination:ocidSetDestination
  ###ラベルの初期化
  set strLabel to ("ページ:" & numChkPageNo) as text
  set ocidLabel to (refMe's NSString's stringWithString:strLabel)
  ###ラベルをセット
  ocidOutLineChild's setLabel:ocidLabel
  ###アクションをセット
  ocidOutLineChild's setAction:ocidSetAction
  ###対象のドキュメントを指定
  ocidOutLineChild's setDocument:ocidActivDoc
  ###ROOTに子要素として入れる
  ocidOutLineRoot's insertChild:ocidOutLineChild atIndex:numChkPageNoJs
  ####カウントアップ
  set numChkPageNoJs to numChkPageNoJs + 1 as integer
  set numChkPageNo to numChkPageNo + 1 as integer
end repeat
####保存
(ocidActivDoc's writeToURL:ocidFilePathURL)


return

|

[Reader]しおりの追加(ページ数分)

Screencapture-20230331-171357


【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()


##################################
#### 文書を開いているか?
##################################
tell application id "com.adobe.Reader"
  activate
  tell active doc
    set numAllPage to do script ("this.numPages;")
    try
      if numAllPage is "undefined" then
        error number -1708
      end if
    on error
      display alert "エラー:文書が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
      return "エラー:文書が選択されていません"
    end try
  end tell
end tell
##################################
#### パス取得
##################################
tell application id "com.adobe.Reader"
  activate
  set objAvtivDoc to active doc
  tell objAvtivDoc
    ####ファイルエリアス取得
    set aliasFilePath to file alias as alias
  end tell
end tell

##################################
### パス関連
##################################
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)

##################################
### 本処理
##################################
##PDF読み込み
set ocidActivDoc to refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL
##ページ数を数える
set numCntPage to ocidActivDoc's pageCount() as integer
##アウトライン=しおりのROOTを取得して
set ocidOutLineRoot to ocidActivDoc's outlineRoot()
###無い場合は作る
if ocidOutLineRoot = missing value then
  set ocidOutLineRoot to refMe's PDFOutline's alloc()'s init()
  ocidActivDoc's setOutlineRoot:ocidOutLineRoot
else
  ###すでにしおりがある場合
  #####ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder"
      activate
    end tell
  else
    tell current application
      activate
    end tell
    display alert "すでに目次があります追加になりが?良いですか?" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 30
  end if
end if


##################################
#### 保存
##################################
tell application id "com.adobe.Reader"
  activate
  set objAvtivDoc to active doc
  tell objAvtivDoc
    set boolMode to modified
    ###変更箇所があるなら保存する
    if boolMode is true then
      save
    end if
  end tell
  close objAvtivDoc
end tell

###############カウンターリセット
set numChkPageNo to 1 as integer
set numChkPageNoJs to 0 as integer

##################################
#### ページ分繰り返し
##################################
repeat numCntPage times
  ####しおりの要素を初期化
  set ocidOutLineChild to refMe's PDFOutline's alloc()'s init()
  ###ページオブジェクト(リンク先のページ)
  set ocidSetPage to ocidActivDoc's pageAtIndex:numChkPageNoJs
  ###ページサイズを取得
  set ocidPageBounds to ocidSetPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox)
  set listPageSize to item 2 of ocidPageBounds as list
  set numW to item 1 of listPageSize as number
  set numH to item 2 of listPageSize as number
  #### Destinationをセット↑ここで求めた値をそのままページ上部
  set ocidPoint to refMe's NSMakePoint(numW, numH)
  set ocidSetDestination to refMe's PDFDestination's alloc()'s initWithPage:ocidSetPage atPoint:ocidPoint
  ###zoom値はお好みで
  ocidSetDestination's setZoom:0.5
  ####ActionDestinationをセット
  set ocidSetAction to refMe's PDFActionGoTo's alloc()'s initWithDestination:ocidSetDestination
  ###表示名  
  set strLabel to ("ページ:" & numChkPageNo) as text
  set ocidLabel to (refMe's NSString's stringWithString:strLabel)
  ocidOutLineChild's setLabel:ocidLabel
  ##アクションをセット
  ocidOutLineChild's setAction:ocidSetAction
  ###値を入れたPDFOutline項目をドキュメントルートにセット
  ocidOutLineChild's setDocument:ocidActivDoc
  ###アウトラインのROOTに子要素として追加
  ocidOutLineRoot's insertChild:ocidOutLineChild atIndex:numChkPageNoJs
  ####カウントアップ
  set numChkPageNoJs to numChkPageNoJs + 1 as integer
  set numChkPageNo to numChkPageNo + 1 as integer
end repeat

####保存
(ocidActivDoc's writeToURL:ocidFilePathURL)


##################################
#### ファイルを開く
##################################
tell application id "com.adobe.Reader"
  activate
  open aliasFilePath options "zoom=50&pagemode=bookmarks"
end tell

return


|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom