« [configCode]Macのモデル名を取得する | トップページ | [TTML]現時点でのまとめ(自分用) »

[Acrobat・AcrobatReader]テキスト注釈の作成者の氏名変更(文字化け対策入り)



Acrobat製品版・AcrobatReader版両方入っています

ダウンロード - chg4anntname.zip




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

[Acrobat]テキスト注釈の作成者の氏名変更(文字化け対策入り).scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005Acrobat 製品版用
006javascriptAPIを利用します
007初期設定はこちら
008https://quicktimer.cocolog-nifty.com/icefloe/2024/12/post-fa9580.html
009
010参考にしてください
011
012
013v1 初回作成
014v1.1 一箇所バンドル指定を間違えていたので修正
015
016com.cocolog-nifty.quicktimer.icefloe *)
017----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
018use AppleScript version "2.8"
019use framework "Foundation"
020use framework "AppKit"
021use scripting additions
022property refMe : a reference to current application
023set appFileManager to refMe's NSFileManager's defaultManager()
024
025set strBundleID to ("com.adobe.Acrobat.Pro") as text
026
027##################################
028#### 文書を開いているか?
029##################################
030tell application id "com.adobe.Acrobat.Pro"
031   activate
032   tell active doc
033      set numAllPage to do script ("this.numPages;")
034      set numNowPage to do script ("this.pageNum;")
035      try
036         if numAllPage is "undefined" then
037            error number -1708
038         end if
039      on error
040         display alert "エラー:文書が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
041         return "エラー:文書が選択されていません"
042      end try
043   end tell
044end tell
045##################################
046#### 注釈を選択しているか?
047##################################
048tell application id "com.adobe.Acrobat.Pro"
049   ####ページ今のページ番号
050   set numNowPage to do script ("this.pageNum;")
051   tell page numNowPage
052      try
053         #### selectedAnnotsがエラーしたら選択していない
054         set theSelectedAnnots to do script ("this.selectedAnnots;")
055         if theSelectedAnnots is "undefined" then
056            error number -1708
057         end if
058         set numLenge to do script ("this.selectedAnnots.length;")
059      on error
060         display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 30
061         return "エラー:注釈が選択されていません"
062      end try
063   end tell
064end tell
065##########################################
066#### ユーザー情報取得
067##########################################
068tell application id "com.adobe.Acrobat.Pro"
069   launch
070   activate
071   set objActivDoc to active doc
072   try
073      ####   アクロバットの設定から氏名を取得する場合
074      set strUserLastNamet to do script ("identity.lastName;") as text
075      set strUserFirstNamet to do script ("identity.firstName;") as text
076      ####   姓名を繋げて
077      set strIdentityName to (strUserLastNamet & strUserFirstNamet) as text
078      if strIdentityName is "" then
079         set strIdentityName to "" as text
080         log "環境設定>>ユーザー情報が登録されていません"
081      else if strIdentityName starts with "?" then
082         set strIdentityName to "" as text
083         log "環境設定>>ユーザー情報が文字バケしています"
084      end if
085   on error
086      set strIdentityName to "" as text
087      log "環境設定>>ユーザー情報が登録されていません"
088   end try
089end tell
090##########################################
091####ダイアログ
092##########################################
093set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
094####ダイアログに指定アプリのアイコンを表示する
095set strIconPath to ""
096###アイコン名をPLISTから取得
097set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
098set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
099set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
100###ICONURLにして
101set strPath to ("Contents/Resources/" & strIconFileName) as text
102set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
103###拡張子の有無チェック
104set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
105if strExtensionName is "" then
106   set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
107end if
108##-->これがアイコンパス
109log ocidIconFilePathURL's absoluteString() as text
110###ICONファイルが実際にあるか?チェック
111set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
112###ICONがみつかない時用にデフォルトを用意する
113if boolExists is false then
114   set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
115else
116   set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
117   set strIconPath to ocidIconFilePathURL's |path|() as text
118end if
119if strIconPath is (missing value) then
120   set strIconPath to ""
121end if
122
123##########デフォルトアンサー
124if strIdentityName is "" then
125   ####OSのログイン名
126   tell application "Finder"
127      set strLongUserName to long user name of (system info) as text
128   end tell
129   set strDefaultAnswer to strLongUserName as text
130   log "環境設定>>ユーザー情報が登録されていません"
131else
132   ###Acrobatのユーザー情報設定
133   set strDefaultAnswer to strIdentityName as text
134end if
135##############################
136#####ダイアログを前面に出す
137##############################
138tell current application
139   set strName to name as text
140end tell
141####スクリプトメニューから実行したら
142if strName is "osascript" then
143   tell application "Finder"
144      activate
145   end tell
146else
147   tell current application
148      activate
149   end tell
150end if
151try
152   set recordResponse to (display dialog "ここに入力した名称に書き換えます" with title "注釈の名称変更します" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 30 without hidden answer)
153on error
154   log "エラーしました"
155   return "エラーしました"
156   error number -128
157end try
158if true is equal to (gave up of recordResponse) then
159   return "時間切れですやりなおしてください"
160   error number -128
161end if
162if "OK" is equal to (button returned of recordResponse) then
163   ####戻りの値を設定します
164   set strResponse to (text returned of recordResponse) as text
165else
166   log "エラーしました"
167   return "エラーしました"
168   error number -128
169end if
170
171
172################################
173### ページ数
174################################
175
176tell application id "com.adobe.Acrobat.Pro"
177   activate
178   tell active doc
179      ####全面のドキュメントの
180      ###      ページ数
181      set numAllPage to do script ("this.numPages;")
182      ###      今のページ番号
183      set numNowPage to do script ("this.pageNum;")
184   end tell
185end tell
186
187################################
188### ロック解除
189################################
190set numAnnoCnt to 0
191repeat numLenge times
192   tell application id "com.adobe.Acrobat.Pro"
193      ########まずはロックを解除する
194      try
195         do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({lock:'false'});")
196         do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({readOnly:'false'});")
197      on error
198         do script ("this.selectedAnnots[" & numAnnoCnt & "].lock = false;")
199         do script ("this.selectedAnnots[" & numAnnoCnt & "].readOnly = false;")
200      end try
201      set numAnnoCnt to numAnnoCnt + 1
202   end tell
203end repeat
204################################
205### 注釈数のカウント
206################################
207set listAnnoID to {} as list
208tell application id "com.adobe.Acrobat.Pro"
209   tell page numNowPage
210      try
211         #####注釈カウント
212         set theSelectedAnnots to do script ("this.selectedAnnots;")
213         set numLenge to do script ("this.selectedAnnots.length;")
214         
215         do script ("var objAllAnnots = this.selectedAnnots;")
216         do script ("var objAllAnnotsLength = this.selectedAnnots.length;")
217         
218      on error
219         display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
220         return
221      end try
222   end tell
223end tell
224################################
225### 注釈の内容をセット
226################################
227set numAnnoCnt to 0
228tell application id "com.adobe.Acrobat.Pro"
229   repeat numLenge times
230      ####注釈の数だけ繰り返し
231      do script ("objAllAnnots[" & numAnnoCnt & "].setProps({ author:\"" & strResponse & "\"});")
232      set numAnnoCnt to numAnnoCnt + 1
233   end repeat
234end tell
235
236
237#display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
238#log ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
239return ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
240
241
242
243###################################
244### バンドルIDからアプリケーションURL
245###################################
246to doGetBundleID2AppURL(argBundleID)
247   set strBundleID to argBundleID as text
248   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
249   ##バンドルIDからアプリケーションのURLを取得
250   set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
251   if ocidAppBundle ≠ (missing value) then
252      set ocidAppPathURL to ocidAppBundle's bundleURL()
253   else if ocidAppBundle = (missing value) then
254      set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
255   end if
256   ##予備(アプリケーションのURL
257   if ocidAppPathURL = (missing value) then
258      tell application "Finder"
259         try
260            set aliasAppApth to (application file id strBundleID) as alias
261            set strAppPath to (POSIX path of aliasAppApth) as text
262            set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
263            set strAppPath to strAppPathStr's stringByStandardizingPath()
264            set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
265         on error
266            return "アプリケーションが見つかりませんでした"
267         end try
268      end tell
269   end if
270   return ocidAppPathURL
271end doGetBundleID2AppURL
AppleScriptで生成しました

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

[Acrobat Reader]テキスト注釈の作成者の氏名変更(文字化け対策入り) .scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005Acrobat Reader
006javascriptAPIを利用します
007初期設定はこちら
008https://quicktimer.cocolog-nifty.com/icefloe/2024/12/post-fa9580.html
009
010参考にしてください
011
012v1 初回作成
013v1.1 一箇所バンドル指定を間違えていたので修正
014
015com.cocolog-nifty.quicktimer.icefloe *)
016----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
017use AppleScript version "2.8"
018use framework "Foundation"
019use framework "AppKit"
020use scripting additions
021property refMe : a reference to current application
022set appFileManager to refMe's NSFileManager's defaultManager()
023
024set strBundleID to ("com.adobe.Reader") as text
025
026##################################
027#### 文書を開いているか?
028##################################
029tell application id "com.adobe.Reader"
030   activate
031   tell active doc
032      set numAllPage to do script ("this.numPages;")
033      set numNowPage to do script ("this.pageNum;")
034      try
035         if numAllPage is "undefined" then
036            error number -1708
037         end if
038      on error
039         display alert "エラー:文書が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
040         return "エラー:文書が選択されていません"
041      end try
042   end tell
043end tell
044##################################
045#### 注釈を選択しているか?
046##################################
047tell application id "com.adobe.Reader"
048   ####ページ今のページ番号
049   set numNowPage to do script ("this.pageNum;")
050   tell page numNowPage
051      try
052         #### selectedAnnotsがエラーしたら選択していない
053         set theSelectedAnnots to do script ("this.selectedAnnots;")
054         if theSelectedAnnots is "undefined" then
055            error number -1708
056         end if
057         set numLenge to do script ("this.selectedAnnots.length;")
058      on error
059         display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 30
060         return "エラー:注釈が選択されていません"
061      end try
062   end tell
063end tell
064##########################################
065#### ユーザー情報取得
066##########################################
067tell application id "com.adobe.Reader"
068   launch
069   activate
070   set objActivDoc to active doc
071   try
072      ####   アクロバットの設定から氏名を取得する場合
073      set strUserLastNamet to do script ("identity.lastName;") as text
074      set strUserFirstNamet to do script ("identity.firstName;") as text
075      ####   姓名を繋げて
076      set strIdentityName to (strUserLastNamet & strUserFirstNamet) as text
077      if strIdentityName is "" then
078         set strIdentityName to "" as text
079         log "環境設定>>ユーザー情報が登録されていません"
080      else if strIdentityName starts with "?" then
081         set strIdentityName to "" as text
082         log "環境設定>>ユーザー情報が文字バケしています"
083      end if
084   on error
085      set strIdentityName to "" as text
086      log "環境設定>>ユーザー情報が登録されていません"
087   end try
088end tell
089##########################################
090####ダイアログ
091##########################################
092set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
093####ダイアログに指定アプリのアイコンを表示する
094set strIconPath to ""
095###アイコン名をPLISTから取得
096set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
097set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
098set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
099###ICONURLにして
100set strPath to ("Contents/Resources/" & strIconFileName) as text
101set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
102###拡張子の有無チェック
103set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
104if strExtensionName is "" then
105   set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
106end if
107##-->これがアイコンパス
108log ocidIconFilePathURL's absoluteString() as text
109###ICONファイルが実際にあるか?チェック
110set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
111###ICONがみつかない時用にデフォルトを用意する
112if boolExists is false then
113   set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
114else
115   set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
116   set strIconPath to ocidIconFilePathURL's |path|() as text
117end if
118if strIconPath is (missing value) then
119   set strIconPath to ""
120end if
121
122##########デフォルトアンサー
123if strIdentityName is "" then
124   ####OSのログイン名
125   tell application "Finder"
126      set strLongUserName to long user name of (system info) as text
127   end tell
128   set strDefaultAnswer to strLongUserName as text
129   log "環境設定>>ユーザー情報が登録されていません"
130else
131   ###Acrobatのユーザー情報設定
132   set strDefaultAnswer to strIdentityName as text
133end if
134##############################
135#####ダイアログを前面に出す
136##############################
137tell current application
138   set strName to name as text
139end tell
140####スクリプトメニューから実行したら
141if strName is "osascript" then
142   tell application "Finder"
143      activate
144   end tell
145else
146   tell current application
147      activate
148   end tell
149end if
150try
151   set recordResponse to (display dialog "ここに入力した名称に書き換えます" with title "注釈の名称変更します" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 30 without hidden answer)
152on error
153   log "エラーしました"
154   return "エラーしました"
155   error number -128
156end try
157if true is equal to (gave up of recordResponse) then
158   return "時間切れですやりなおしてください"
159   error number -128
160end if
161if "OK" is equal to (button returned of recordResponse) then
162   ####戻りの値を設定します
163   set strResponse to (text returned of recordResponse) as text
164else
165   log "エラーしました"
166   return "エラーしました"
167   error number -128
168end if
169
170
171################################
172### ページ数
173################################
174
175tell application id "com.adobe.Reader"
176   activate
177   tell active doc
178      ####全面のドキュメントの
179      ###      ページ数
180      set numAllPage to do script ("this.numPages;")
181      ###      今のページ番号
182      set numNowPage to do script ("this.pageNum;")
183   end tell
184end tell
185
186################################
187### ロック解除
188################################
189set numAnnoCnt to 0
190repeat numLenge times
191   tell application id "com.adobe.Reader"
192      ########まずはロックを解除する
193      try
194         do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({lock:'false'});")
195         do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({readOnly:'false'});")
196      on error
197         do script ("this.selectedAnnots[" & numAnnoCnt & "].lock = false;")
198         do script ("this.selectedAnnots[" & numAnnoCnt & "].readOnly = false;")
199      end try
200      set numAnnoCnt to numAnnoCnt + 1
201   end tell
202end repeat
203################################
204### 注釈数のカウント
205################################
206set listAnnoID to {} as list
207tell application id "com.adobe.Reader"
208   tell page numNowPage
209      try
210         #####注釈カウント
211         set theSelectedAnnots to do script ("this.selectedAnnots;")
212         set numLenge to do script ("this.selectedAnnots.length;")
213         
214         do script ("var objAllAnnots = this.selectedAnnots;")
215         do script ("var objAllAnnotsLength = this.selectedAnnots.length;")
216         
217      on error
218         display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
219         return
220      end try
221   end tell
222end tell
223################################
224### 注釈の内容をセット
225################################
226set numAnnoCnt to 0
227tell application id "com.adobe.Reader"
228   repeat numLenge times
229      ####注釈の数だけ繰り返し
230      do script ("objAllAnnots[" & numAnnoCnt & "].setProps({ author:\"" & strResponse & "\"});")
231      set numAnnoCnt to numAnnoCnt + 1
232   end repeat
233end tell
234
235
236#display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
237#log ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
238return ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
239
240
241
242###################################
243### バンドルIDからアプリケーションURL
244###################################
245to doGetBundleID2AppURL(argBundleID)
246   set strBundleID to argBundleID as text
247   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
248   ##バンドルIDからアプリケーションのURLを取得
249   set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
250   if ocidAppBundle ≠ (missing value) then
251      set ocidAppPathURL to ocidAppBundle's bundleURL()
252   else if ocidAppBundle = (missing value) then
253      set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
254   end if
255   ##予備(アプリケーションのURL
256   if ocidAppPathURL = (missing value) then
257      tell application "Finder"
258         try
259            set aliasAppApth to (application file id strBundleID) as alias
260            set strAppPath to (POSIX path of aliasAppApth) as text
261            set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
262            set strAppPath to strAppPathStr's stringByStandardizingPath()
263            set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
264         on error
265            return "アプリケーションが見つかりませんでした"
266         end try
267      end tell
268   end if
269   return ocidAppPathURL
270end doGetBundleID2AppURL
AppleScriptで生成しました

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

#!/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.8"
use framework "Foundation"
use framework "AppKit"
#use framework "Quartz"
#use framework "PDFKit"
#use framework "QuartzCore"
#use framework "CoreGraphics"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()

set strBundleID to ("com.adobe.Acrobat.Pro") as text

##################################
#### 文書を開いているか?
##################################
tell application id "com.adobe.Acrobat.Pro"
activate
  tell active doc
    set numAllPage to do script ("this.numPages;")
    set numNowPage to do script ("this.pageNum;")
    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.Acrobat.Pro"
  ####ページ今のページ番号
  set numNowPage to do script ("this.pageNum;")
  tell page numNowPage
    try
      #### selectedAnnotsがエラーしたら選択していない
      set theSelectedAnnots to do script ("this.selectedAnnots;")
      if theSelectedAnnots is "undefined" then
        error number -1708
      end if
      set numLenge to do script ("this.selectedAnnots.length;")
    on error
display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 30
return "エラー:注釈が選択されていません"
    end try
  end tell
end tell
##########################################
#### ユーザー情報取得
##########################################
tell application id "com.adobe.Acrobat.Pro"
launch
activate
  set objActivDoc to active doc
  try
    #### アクロバットの設定から氏名を取得する場合
    set strUserLastNamet to do script ("identity.lastName;") as text
    set strUserFirstNamet to do script ("identity.firstName;") as text
    #### 姓名を繋げて
    set strIdentityName to (strUserLastNamet & strUserFirstNamet) as text
    if strIdentityName is "" then
      set strIdentityName to "" as text
log "環境設定>>ユーザー情報が登録されていません"
    else if strIdentityName starts with "?" then
      set strIdentityName to "" as text
log "環境設定>>ユーザー情報が文字バケしています"
    end if
  on error
    set strIdentityName to "" as text
log "環境設定>>ユーザー情報が登録されていません"
  end try
end tell
##########################################
####ダイアログ
##########################################
set ocidAppPathURL to doGetBundleID2AppURL(strBundleID)
####ダイアログに指定アプリのアイコンを表示する
set strIconPath to ""
###アイコン名をPLISTから取得
set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  set strIconPath to ocidIconFilePathURL's |path|() as text
end if
if strIconPath is (missing value) then
  set strIconPath to ""
end if

##########デフォルトアンサー
if strIdentityName is "" then
  ####OSのログイン名
  tell application "Finder"
    set strLongUserName to long user name of (system info) as text
  end tell
  set strDefaultAnswer to strLongUserName as text
log "環境設定>>ユーザー情報が登録されていません"
else
  ###Acrobatのユーザー情報設定
  set strDefaultAnswer to strIdentityName as text
end if
##############################
#####ダイアログを前面に出す
##############################
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
try
  set recordResponse to (display dialog "ここに入力した名称に書き換えます" with title "注釈の名称変更します" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 30 without hidden answer)
on error
log "エラーしました"
return "エラーしました"
  error number -128
end try
if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
  error number -128
end if
if "OK" is equal to (button returned of recordResponse) then
  ####戻りの値を設定します
  set strResponse to (text returned of recordResponse) as text
else
log "エラーしました"
return "エラーしました"
  error number -128
end if


################################
### ページ数
################################

tell application "Adobe Acrobat"
activate
  tell active doc
    ####全面のドキュメントの
    ### ページ数
    set numAllPage to do script ("this.numPages;")
    ### 今のページ番号
    set numNowPage to do script ("this.pageNum;")
  end tell
end tell

################################
### ロック解除
################################
set numAnnoCnt to 0
repeat numLenge times
  tell application id "com.adobe.Acrobat.Pro"
    ########まずはロックを解除する
    try
do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({lock:'false'});")
do script ("this.selectedAnnots[" & numAnnoCnt & "].setProps({readOnly:'false'});")
    on error
do script ("this.selectedAnnots[" & numAnnoCnt & "].lock = false;")
do script ("this.selectedAnnots[" & numAnnoCnt & "].readOnly = false;")
    end try
    set numAnnoCnt to numAnnoCnt + 1
  end tell
end repeat
################################
### 注釈数のカウント
################################
set listAnnoID to {} as list
tell application id "com.adobe.Acrobat.Pro"
  tell page numNowPage
    try
      #####注釈カウント
      set theSelectedAnnots to do script ("this.selectedAnnots;")
      set numLenge to do script ("this.selectedAnnots.length;")
      
do script ("var objAllAnnots = this.selectedAnnots;")
do script ("var objAllAnnotsLength = this.selectedAnnots.length;")
      
    on error
display alert "エラー:注釈が選択されていません" buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 10
return
    end try
  end tell
end tell
################################
### 注釈の内容をセット
################################
set numAnnoCnt to 0
tell application id "com.adobe.Acrobat.Pro"
  repeat numLenge times
    ####注釈の数だけ繰り返し
do script ("objAllAnnots[" & numAnnoCnt & "].setProps({ author:\"" & strResponse & "\"});")
    set numAnnoCnt to numAnnoCnt + 1
  end repeat
end tell


#display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
#log ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
return ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"



###################################
### バンドルIDからアプリケーションURL
###################################
to doGetBundleID2AppURL(argBundleID)
  set strBundleID to argBundleID as text
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ##バンドルIDからアプリケーションのURLを取得
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleID))
  end if
  ##予備(アプリケーションのURL)
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
        set aliasAppApth to (application file id strBundleID) as alias
        set strAppPath to (POSIX path of aliasAppApth) as text
        set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
        set strAppPath to strAppPathStr's stringByStandardizingPath()
        set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
  end if
return ocidAppPathURL
end doGetBundleID2AppURL


|

« [configCode]Macのモデル名を取得する | トップページ | [TTML]現時点でのまとめ(自分用) »

Acrobat Annotation」カテゴリの記事