[Acrobat]PDFにウォーターマーク・透かしを入れる(画像ファイルでもOK) 少し修正
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # 透かしにしたい画像はPNGやJPEGでもOK |
005 | # Watermarkフォルダに入れてください |
006 | (* |
007 | PDFの透かしの機能 |
008 | ISO 32000-1で標準化されていないので |
009 | 結果は本当に閲覧ソフト次第でマチマチです |
010 | Acrobatで設定するのでAcroabtで閲覧するのを前提です |
011 | |
012 | *) |
013 | # com.cocolog-nifty.quicktimer.icefloe |
014 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
015 | use AppleScript version "2.8" |
016 | use framework "Foundation" |
017 | use framework "AppKit" |
018 | use scripting additions |
019 | property refMe : a reference to current application |
020 | |
021 | |
022 | |
023 | |
024 | ################################## |
025 | #設定可能な値 |
026 | #開始ページ |
027 | set nStart to ("0") as «class utf8» |
028 | #透明度 0−1 |
029 | set nOpacity to ("0.2") as «class utf8» |
030 | # true false |
031 | #値にパーセントを使う |
032 | set bPercentage to ("false") as «class utf8» |
033 | #自動修正するか |
034 | set bFixedPrint to ("false") as «class utf8» |
035 | #ページの上に透かしを入れる |
036 | set bOnTop to ("true") as «class utf8» |
037 | #画面表示するか |
038 | set bOnScreen to ("true") as «class utf8» |
039 | #印刷時出力するか |
040 | set bOnPrint to ("true") as «class utf8» |
041 | |
042 | |
043 | ################################## |
044 | #Acrobatが起動しているか? |
045 | tell application "System Events" to launch |
046 | tell application "System Events" |
047 | set listAppTitile to (name of (every application process)) as list |
048 | end tell |
049 | if listAppTitile contains "AdobeAcrobat" then |
050 | log "Acrobat起動済み" |
051 | else |
052 | set strName to (name of current application) as text |
053 | if strName is "osascript" then |
054 | tell application "Finder" to activate |
055 | else |
056 | tell current application to activate |
057 | end if |
058 | set listBotton to {"終了", "続ける"} as list |
059 | set recordResponse to display alert "処理中断" message "アクロバットが起動していません" giving up after 4 buttons listBotton default button (item 1 of listBotton) cancel button (item 1 of listBotton) |
060 | if (gave up of recordResponse) is true then |
061 | return "時間切れ:処理中止" |
062 | else if (button returned of recordResponse) is "" then |
063 | return "戻り値ボタン不正:処理中止" |
064 | else if (button returned of recordResponse) is (item 1 of listBotton) then |
065 | return "ボタン終了選択:処理終了" |
066 | else if (button returned of recordResponse) is (item 2 of listBotton) then |
067 | log "処理継続アクロバットを起動します" |
068 | tell application "Adobe Acrobat" to launch |
069 | #起動確認 |
070 | repeat 60 times |
071 | tell application "Adobe Acrobat" |
072 | activate |
073 | set boolFrontMost to frontmost as boolean |
074 | end tell |
075 | if boolFrontMost is true then |
076 | exit repeat |
077 | else |
078 | delay 0.2 |
079 | end if |
080 | end repeat |
081 | else |
082 | display alert "処理中断" message "アクロバットが起動していません" giving up after 2 |
083 | return "アクロバットが起動していません" |
084 | end if |
085 | end if |
086 | |
087 | ################################## |
088 | #PDFファイルを開いているか? |
089 | tell application "Adobe Acrobat" |
090 | activate |
091 | set numCntPDFWindow to (count of PDF Window) as integer |
092 | end tell |
093 | if numCntPDFWindow = 0 then |
094 | log "PDFを開いていません" |
095 | set strName to (name of current application) as text |
096 | if strName is "osascript" then |
097 | tell application "Finder" to activate |
098 | else |
099 | tell current application to activate |
100 | end if |
101 | set listBotton to {"終了", "続ける"} as list |
102 | set recordResponse to display alert "処理中断" message "PDFを開いていません" giving up after 4 buttons listBotton default button (item 1 of listBotton) cancel button (item 1 of listBotton) |
103 | if (gave up of recordResponse) is true then |
104 | return "時間切れ:処理中止" |
105 | else if (button returned of recordResponse) is "" then |
106 | return "戻り値ボタン不正:処理中止" |
107 | else if (button returned of recordResponse) is (item 1 of listBotton) then |
108 | return "ボタン終了選択:処理終了" |
109 | else if (button returned of recordResponse) is (item 2 of listBotton) then |
110 | log "処理継続PDFを開きます" |
111 | set strName to (name of current application) as text |
112 | if strName is "osascript" then |
113 | tell application "Finder" to activate |
114 | else |
115 | tell current application to activate |
116 | end if |
117 | set appFileManager to refMe's NSFileManager's defaultManager() |
118 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
119 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
120 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
121 | set listUTI to {"com.adobe.pdf"} |
122 | set strMes to ("PDFファイルを選んでください") as text |
123 | set strPrompt to ("PDFファイルを選んでください") as text |
124 | try |
125 | ### ファイル選択 |
126 | 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 |
127 | tell application "Adobe Acrobat" |
128 | activate |
129 | open file aliasFilePath |
130 | end tell |
131 | on error |
132 | log "エラーしました" |
133 | return "エラーしました" |
134 | end try |
135 | else |
136 | display alert "処理中断" message "PDFドキュメントを開いていません" giving up after 2 |
137 | return "PDFドキュメントを開いていません" |
138 | end if |
139 | else |
140 | log "PDFを開いているので処理継続" |
141 | tell application "Adobe Acrobat" |
142 | activate |
143 | tell active doc |
144 | #パス |
145 | set aliasFilePath to file alias as alias |
146 | end tell |
147 | end tell |
148 | end if |
149 | tell application "Adobe Acrobat" |
150 | tell active doc |
151 | #ページ数 |
152 | set numCntAllPdfPage to (count of every page) as integer |
153 | end tell |
154 | end tell |
155 | |
156 | |
157 | #開いたPDFのパスとファイル名 |
158 | set strPDFFilePath to (POSIX path of aliasFilePath) as text |
159 | set ocidPDFFilePathStr to refMe's NSString's stringWithString:(strPDFFilePath) |
160 | set ocidPDFFilePath to ocidPDFFilePathStr's stringByStandardizingPath() |
161 | set ocidPdfFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPDFFilePath) isDirectory:false) |
162 | set strPdfFileName to (ocidPdfFilePathURL's lastPathComponent()) as text |
163 | set ocidPdfFileName to ocidPdfFilePathURL's lastPathComponent() |
164 | |
165 | ############################ |
166 | #このスクリプトのパス |
167 | set aliasPathToMe to (path to me) as alias |
168 | set strPathToMe to (POSIX path of aliasPathToMe) as text |
169 | set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe) |
170 | set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath() |
171 | set ocidPathToMeURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:false) |
172 | #JSファイルの入っているフォルダ |
173 | set ocidConteinerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent() |
174 | set ocidWatermarkDirPathURL to ocidConteinerDirPathURL's URLByAppendingPathComponent:("Watermark") isDirectory:(true) |
175 | ###コンテンツを収集する 第一階層のみ |
176 | set appFileManager to refMe's NSFileManager's defaultManager() |
177 | set ocidPropertiesArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
178 | ocidPropertiesArray's addObject:(refMe's NSURLContentTypeKey) |
179 | ocidPropertiesArray's addObject:(refMe's NSURLNameKey) |
180 | ocidPropertiesArray's addObject:(refMe's NSURLPathKey) |
181 | set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles) |
182 | set ocidEmuDict to appFileManager's enumeratorAtURL:(ocidWatermarkDirPathURL) includingPropertiesForKeys:(ocidPropertiesArray) options:(ocidOption) errorHandler:(reference) |
183 | #収集するUTI |
184 | set listUTI to {"public.png", "com.adobe.pdf", "public.jpeg"} as list |
185 | |
186 | #収集したURLを分別格納用 |
187 | set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
188 | set ocidEmuFileURLArray to ocidEmuDict's allObjects() |
189 | ####URLの数だけ繰り返す |
190 | repeat with itemURL in ocidEmuFileURLArray |
191 | #判定 |
192 | set listResponse to (itemURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference)) |
193 | if (item 1 of listResponse) is (true) then |
194 | set ocidUTType to (item 2 of listResponse) |
195 | #初期値はFALSE |
196 | set boolUTIContain to false as boolean |
197 | #listUTIの数だけ繰り返し |
198 | repeat with itemUTI in listUTI |
199 | #親要素(この属性なら処理する)のUTType |
200 | set ocidChkUTType to (refMe's UTType's typeWithIdentifier:(itemUTI)) |
201 | if ocidUTType = ocidChkUTType then |
202 | set boolUTIContain to true as boolean |
203 | end if |
204 | end repeat |
205 | #チェックが終わったので |
206 | #初期値がTrueに変わっていたらそれは画像か?PDF |
207 | if boolUTIContain is true then |
208 | (ocidFilePathURLArray's addObject:(itemURL)) |
209 | end if |
210 | end if |
211 | end repeat |
212 | #ダイアログ用のファイル名の収集 |
213 | set ocidFileNameDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
214 | repeat with itemFilePathURL in ocidFilePathURLArray |
215 | set ocidFileName to itemFilePathURL's lastPathComponent() |
216 | (ocidFileNameDict's setValue:(itemFilePathURL) forKey:(ocidFileName)) |
217 | end repeat |
218 | #キー=フィアル名を取り出してソートしておく |
219 | set ocidJsAllKey to ocidFileNameDict's allKeys() |
220 | set ocidSortedJsAllKey to ocidJsAllKey's sortedArrayUsingSelector:("localizedStandardCompare:") |
221 | set listFileName to (ocidSortedJsAllKey) as list |
222 | |
223 | |
224 | ###ダイアログを前面に出す |
225 | tell current application |
226 | set strName to name as text |
227 | end tell |
228 | if strName is "osascript" then |
229 | tell application "Finder" to activate |
230 | else |
231 | tell current application to activate |
232 | end if |
233 | try |
234 | set listResponse to (choose from list listFileName with title "選んでください" with prompt "【透かしになるイメージを選んでください】" default items (item 2 of listFileName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list |
235 | on error |
236 | log "エラーしました" |
237 | return "エラーしました" |
238 | end try |
239 | if (item 1 of listResponse) is false then |
240 | return "キャンセルしました" |
241 | end if |
242 | |
243 | |
244 | ###ダイアログの戻り値 |
245 | set strWatermarkFileName to (item 1 of listResponse) as text |
246 | ###レコードから取り出す |
247 | set ocidWatermarkFilePathURL to ocidFileNameDict's valueForKey:(strWatermarkFileName) |
248 | ##拡張子 |
249 | set strExtensionName to (ocidWatermarkFilePathURL's pathExtension()) as text |
250 | if strExtensionName is ("pdf") then |
251 | set strWatermarkFilePath to (ocidWatermarkFilePathURL's |path|()) as «class utf8» |
252 | else |
253 | ###ディレクトリ 再起動時に自動削除 |
254 | set appFileManager to refMe's NSFileManager's defaultManager() |
255 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
256 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
257 | set ocidUUIDString to ocidUUID's UUIDString |
258 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true |
259 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
260 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
261 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
262 | #保存先 |
263 | set ocidMakePdfFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Watermark.pdf") isDirectory:(false) |
264 | #NSDATAに読み込んで |
265 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
266 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidWatermarkFilePathURL) options:(ocidOption) |error| :(reference) |
267 | if (item 2 of listResponse) = (missing value) then |
268 | set ocidReadData to (item 1 of listResponse) |
269 | else if (item 2 of listResponse) ≠ (missing value) then |
270 | set strErrorNO to (item 2 of listResponse)'s code() as text |
271 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
272 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
273 | return "エラーしました" & strErrorNO & strErrorMes |
274 | end if |
275 | #NSIMAGEに変換 |
276 | set ocidImageData to refMe's NSImage's alloc()'s initWithData:(ocidReadData) |
277 | ####ドキュメントの初期化 |
278 | #PDFにする |
279 | set ocidActiveDoc to refMe's PDFDocument's alloc()'s init() |
280 | set ocidPDFPage to refMe's PDFPage's alloc()'s initWithImage:(ocidImageData) |
281 | ocidActiveDoc's insertPage:(ocidPDFPage) atIndex:(0) |
282 | set boolDone to (ocidActiveDoc's writeToURL:(ocidMakePdfFilePathURL) withOptions:(missing value)) |
283 | set strWatermarkFilePath to (ocidMakePdfFilePathURL's |path|()) as «class utf8» |
284 | end if |
285 | |
286 | ######################## |
287 | #印字位置 |
288 | set listPrintPos to {"センター", "センター45度回転", "センター45度拡大", "上左", "上中央", "上右", "下左", "下中央", "下右"} as list |
289 | ###ダイアログを前面に出す |
290 | tell current application |
291 | set strName to name as text |
292 | end tell |
293 | if strName is "osascript" then |
294 | tell application "Finder" to activate |
295 | else |
296 | tell current application to activate |
297 | end if |
298 | try |
299 | set listResponse to (choose from list listPrintPos with title "選んでください" with prompt "【印字位置を選んでください】" default items (item 2 of listPrintPos) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list |
300 | on error |
301 | log "エラーしました" |
302 | return "エラーしました" |
303 | end try |
304 | if (item 1 of listResponse) is false then |
305 | return "キャンセルしました" |
306 | end if |
307 | set strPrintPos to (item 1 of listResponse) as text |
308 | if strPrintPos is "センター" then |
309 | #回転 |
310 | set nRotation to ("0") as «class utf8» |
311 | #ポジション |
312 | # left center right |
313 | set nHorizAlign to ("app.constants.align.center") as «class utf8» |
314 | # top center bottom |
315 | set nVertAlign to ("app.constants.align.center") as «class utf8» |
316 | #位置調整 PT 左右 |
317 | set nHorizValue to ("0") as «class utf8» |
318 | #位置調整 PT 上下 |
319 | set nVertValue to ("0") as «class utf8» |
320 | #拡大縮小 1ーXXX |
321 | set nScale to ("1") as «class utf8» |
322 | |
323 | else if strPrintPos is "センター45度回転" then |
324 | #回転 |
325 | set nRotation to ("45") as «class utf8» |
326 | #ポジション |
327 | # left center right |
328 | set nHorizAlign to ("app.constants.align.center") as «class utf8» |
329 | # top center bottom |
330 | set nVertAlign to ("app.constants.align.center") as «class utf8» |
331 | #位置調整 PT 左右 |
332 | set nHorizValue to ("0") as «class utf8» |
333 | #位置調整 PT 上下 |
334 | set nVertValue to ("0") as «class utf8» |
335 | #拡大縮小 1ーXXX |
336 | set nScale to ("1") as «class utf8» |
337 | |
338 | else if strPrintPos is "センター45度拡大" then |
339 | #回転 |
340 | set nRotation to ("45") as «class utf8» |
341 | #ポジション |
342 | # left center right |
343 | set nHorizAlign to ("app.constants.align.center") as «class utf8» |
344 | # top center bottom |
345 | set nVertAlign to ("app.constants.align.center") as «class utf8» |
346 | #位置調整 PT 左右 |
347 | set nHorizValue to ("0") as «class utf8» |
348 | #位置調整 PT 上下 |
349 | set nVertValue to ("0") as «class utf8» |
350 | #拡大率計算 |
351 | set ocidPDFDoc to refMe's PDFDocument's alloc()'s initWithURL:(ocidWatermarkFilePathURL) |
352 | set ocidPDFPage to ocidPDFDoc's pageAtIndex:(0) |
353 | set ocidBounds to ocidPDFPage's boundsForBox:(refMe's kPDFDisplayBoxCropBox) |
354 | set ocidW to refMe's NSRect's NSWidth(ocidBounds) as number |
355 | set ocidH to refMe's NSRect's NSHeight(ocidBounds) as number |
356 | |
357 | tell application "Adobe Acrobat" |
358 | tell active doc |
359 | tell first page |
360 | set listCropBox to crop box as list |
361 | set numW to item 2 of listCropBox as integer |
362 | set numH to item 3 of listCropBox as integer |
363 | end tell |
364 | end tell |
365 | end tell |
366 | #拡大縮小 1ーXXX |
367 | set nScale to ("3.6") as «class utf8» |
368 | |
369 | else if strPrintPos is "上左" then |
370 | #回転 |
371 | set nRotation to ("0") as «class utf8» |
372 | #ポジション |
373 | # left center right |
374 | set nHorizAlign to ("app.constants.align.left") as «class utf8» |
375 | # top center bottom |
376 | set nVertAlign to ("app.constants.align.top") as «class utf8» |
377 | #位置調整 PT 左右 |
378 | set nHorizValue to ("10") as «class utf8» |
379 | #位置調整 PT 上下 |
380 | set nVertValue to ("-10") as «class utf8» |
381 | #拡大縮小 1ーXXX |
382 | set nScale to ("1") as «class utf8» |
383 | |
384 | else if strPrintPos is "上中央" then |
385 | #回転 |
386 | set nRotation to ("0") as «class utf8» |
387 | #ポジション |
388 | # left center right |
389 | set nHorizAlign to ("app.constants.align.center") as «class utf8» |
390 | # top center bottom |
391 | set nVertAlign to ("app.constants.align.top") as «class utf8» |
392 | #位置調整 PT 左右 |
393 | set nHorizValue to ("0") as «class utf8» |
394 | #位置調整 PT 上下 |
395 | set nVertValue to ("-10") as «class utf8» |
396 | #拡大縮小 1ーXXX |
397 | set nScale to ("1") as «class utf8» |
398 | |
399 | else if strPrintPos is "上右" then |
400 | #回転 |
401 | set nRotation to ("0") as «class utf8» |
402 | #ポジション |
403 | # left center right |
404 | set nHorizAlign to ("app.constants.align.right") as «class utf8» |
405 | # top center bottom |
406 | set nVertAlign to ("app.constants.align.top") as «class utf8» |
407 | #位置調整 PT 左右 |
408 | set nHorizValue to ("-10") as «class utf8» |
409 | #位置調整 PT 上下 |
410 | set nVertValue to ("-10") as «class utf8» |
411 | #拡大縮小 1ーXXX |
412 | set nScale to ("1") as «class utf8» |
413 | |
414 | else if strPrintPos is "下左" then |
415 | #回転 |
416 | set nRotation to ("0") as «class utf8» |
417 | #ポジション |
418 | # left center right |
419 | set nHorizAlign to ("app.constants.align.left") as «class utf8» |
420 | # top center bottom |
421 | set nVertAlign to ("app.constants.align.bottom") as «class utf8» |
422 | #位置調整 PT 左右 |
423 | set nHorizValue to ("10") as «class utf8» |
424 | #位置調整 PT 上下 |
425 | set nVertValue to ("10") as «class utf8» |
426 | #拡大縮小 1ーXXX |
427 | set nScale to ("1") as «class utf8» |
428 | |
429 | else if strPrintPos is "下中央" then |
430 | #回転 |
431 | set nRotation to ("0") as «class utf8» |
432 | #ポジション |
433 | # left center right |
434 | set nHorizAlign to ("app.constants.align.center") as «class utf8» |
435 | # top center bottom |
436 | set nVertAlign to ("app.constants.align.bottom") as «class utf8» |
437 | #位置調整 PT 左右 |
438 | set nHorizValue to ("0") as «class utf8» |
439 | #位置調整 PT 上下 |
440 | set nVertValue to ("10") as «class utf8» |
441 | #拡大縮小 1ーXXX |
442 | set nScale to ("1") as «class utf8» |
443 | |
444 | else if strPrintPos is "下右" then |
445 | #回転 |
446 | set nRotation to ("0") as «class utf8» |
447 | #ポジション |
448 | # left center right |
449 | set nHorizAlign to ("app.constants.align.right") as «class utf8» |
450 | # top center bottom |
451 | set nVertAlign to ("app.constants.align.bottom") as «class utf8» |
452 | #位置調整 PT 左右 |
453 | set nHorizValue to ("-10") as «class utf8» |
454 | #位置調整 PT 上下 |
455 | set nVertValue to ("10") as «class utf8» |
456 | #拡大縮小 1ーXXX |
457 | set nScale to ("1") as «class utf8» |
458 | |
459 | end if |
460 | |
461 | ######################## |
462 | #Watermark用のPDFのパス |
463 | set cDIPath to (strWatermarkFilePath) as «class utf8» |
464 | #終了ページ |
465 | set strEndPage to (numCntAllPdfPage - 1) as text |
466 | set nEnd to strEndPage as «class utf8» |
467 | #WatermarkになるPDFの何ページ目を透かしにする? |
468 | set nSourcePage to ("0") as «class utf8» |
469 | |
470 | |
471 | set strJs to ("this.addWatermarkFromFile({cDIPath: \"" & cDIPath & "\",nSourcePage: " & nSourcePage & ",nStart: " & nStart & ",nEnd: " & nEnd & ",nRotation: " & nRotation & ",nHorizAlign: " & nHorizAlign & ",nVertAlign: " & nVertAlign & ",nHorizValue: " & nHorizValue & ",nVertValue: " & nVertValue & ",bPercentage: " & bPercentage & ",nScale: " & nScale & ",nOpacity: " & nOpacity & ",bOnTop: " & bOnTop & ",bFixedPrint: " & bFixedPrint & ",bOnScreen: " & bOnScreen & ",bOnPrint: " & bOnPrint & "});") as «class utf8» |
472 | |
473 | log strJs |
474 | tell application "Adobe Acrobat" |
475 | activate |
476 | try |
477 | do script strJs |
478 | on error |
479 | return "Js実行でエラーしました" |
480 | end try |
481 | end tell |
482 | |
483 | |
484 | ##保存をJSに行わせる |
485 | set ocidJsDirPathURL to ocidConteinerDirPathURL's URLByAppendingPathComponent:("JavaScript") isDirectory:(true) |
486 | set ocidJsFilePathURL to ocidJsDirPathURL's URLByAppendingPathComponent:("doSaveFile.js") isDirectory:(false) |
487 | ####### |
488 | #JSファイルをNSDATAとして読み込み |
489 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
490 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidJsFilePathURL) options:(ocidOption) |error| :(reference) |
491 | if (item 2 of listResponse) = (missing value) then |
492 | set ocidReadData to (item 1 of listResponse) |
493 | else if (item 2 of listResponse) ≠ (missing value) then |
494 | set strErrorNO to (item 2 of listResponse)'s code() as text |
495 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
496 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
497 | return "エラーしました" & strErrorNO & strErrorMes |
498 | end if |
499 | ####### |
500 | #NSDATAを可変テキストに変更 |
501 | set ocidTextEnc to (refMe's NSUTF8StringEncoding) |
502 | set ocidReadString to refMe's NSMutableString's alloc()'s initWithData:(ocidReadData) encoding:(ocidTextEnc) |
503 | set strReadString to ocidReadString as text |
504 | |
505 | tell application "Adobe Acrobat" |
506 | activate |
507 | try |
508 | do script strReadString |
509 | on error |
510 | return "Js実行でエラーしました" |
511 | end try |
512 | end tell |
513 | |
514 | |
515 | |
AppleScriptで生成しました |
| 固定リンク