PDFKit DocumentPermissions

PDFパスワード設定 (UIの呼び出しを SystemUIServer に変更した)



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions

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

PDFパスワード設定.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004別名で保存からアプリケーションにすると便利です
005
006パスワードは自動生成UUIDを使っています
007PWを記載したテキストファイルも同時に保存します
008
009v2 選択内容に依存がある場合の対応をした
010v3 UIの呼び出しを SystemUIServer に変更した
011v3.1 微修正 使っていないframeworkをコメントアウト
012 com.cocolog-nifty.quicktimer.icefloe *)
013----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
014use AppleScript version "2.8"
015use framework "Foundation"
016use framework "AppKit"
017use framework "PDFKit"
018#use framework "Quartz"
019#use framework "QuartzCore"
020#use framework "CoreGraphics"
021use scripting additions
022
023property refMe : a reference to current application
024
025####所有者パスワード
026property boolOwnerPW : true as boolean
027####アクアセス権
028##   property intAllowNo : 0 as integer
029(*
030例:全部OKの場合 255 全部ロックは0
031許可する番号を『足し算』する
032低解像度印刷      (*1*) refMe's PDFAllowsLowQualityPrinting
033高解像度印刷      (*2*) refMe's PDFAllowsHighQualityPrinting
034文書に変更         (*4*) refMe's PDFAllowsDocumentChanges
035アッセンブリ      (*8*) refMe's PDFAllowsDocumentAssembly
036コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
037アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
038コメント注釈      (*64*) refMe's PDFAllowsCommenting
039フォーム入力      (*128*) refMe's PDFAllowsFormFieldEntry
040
041log refMe's PDFAllowsLowQualityPrinting as integer
042log refMe's PDFAllowsHighQualityPrinting as integer
043log refMe's PDFAllowsDocumentChanges as integer
044log refMe's PDFAllowsDocumentAssembly as integer
045log refMe's PDFAllowsContentCopying as integer
046log refMe's PDFAllowsContentAccessibility as integer
047log refMe's PDFAllowsCommenting as integer
048log refMe's PDFAllowsFormFieldEntry as integer
049
050*)
051
052on run
053   ###ダイアログ
054   set strName to (name of current application) as text
055   if strName is "osascript" then
056      tell application "SystemUIServer" to activate
057   else
058      tell current application to activate
059   end if
060   set appFileManager to refMe's NSFileManager's defaultManager()
061   set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
062   set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:(0)
063   set listChooseFileUTI to {"com.adobe.pdf"} as list
064   set strPromptText to "PDFファイルを選んでください" as text
065   tell application "SystemUIServer"
066      activate
067      set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
068   end tell
069   tell application "SystemUIServer" to quit
070   #選択済みファイルリストをOpenに渡す
071   open listDropObject
072   tell application "SystemUIServer" to quit
073end run
074
075on open listDropObject
076   ##############################
077   set recordOption to {|0開封PW|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
078   #↑のレコードからキーだけを取り出す
079   set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s init()
080   ocidOptionDict's setDictionary:(recordOption)
081   #キーを取り出して
082   set ocidAllKeys to ocidOptionDict's allKeys()
083   #正順に並び替え
084   set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
085   #ダイアログ用にArrayをリストにしておく
086   set listAllKeys to ocidSortedArray as list
087   ###ダイアログを前面に出す
088   set strName to (name of current application) as text
089   if strName is "osascript" then
090      tell application "SystemUIServer" to activate
091   else
092      tell current application to activate
093   end if
094   ###
095   set strTitle to "『禁止設定する』オプション選択(複数可)" as text
096   set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンドキーを押しながらクリック\r組み合わせ留意点\r例:\r低解像度印刷の禁止は<高解像度の印刷の禁止に内包されるので無意味な選択になる組み合わせがあります" as text
097   try
098      tell application "SystemUIServer"
099         activate
100         set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
101      end tell
102   on error
103      tell application "SystemUIServer" to quit
104      log "エラーしました"
105      return "エラーしました"
106      error "エラーしました" number -200
107   end try
108   tell application "SystemUIServer" to quit
109   if listResponse = {} then
110      log "何も選択していない"
111      set boolOpenPW to false as boolean
112      set intAllowNo to 0 as integer
113   else if (item 1 of listResponse) is false then
114      return "キャンセルしました"
115      error "キャンセルしました" number -200
116   else
117      set boolOpenPW to false as boolean
118      set intAllowNo to 0 as integer
119      repeat with itemResponse in listResponse
120         set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
121         #戻り値が999ならOPEN時のパスワード設定をする
122         if intValue = 999 then
123            set boolOpenPW to true as boolean
124         else
125            set intAllowNo to intAllowNo + intValue
126         end if
127      end repeat
128   end if
129   ##許可番号
130   set intAllowNo to (255 - intAllowNo) as integer
131   
132   ########################################
133   #実際の処理するPDFURLを格納するリスト
134   set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
135   ###ドロップされたエイリアスの数だけ繰り返し
136   repeat with itemDropObject in listDropObject
137      ###処理除外するエイリアスを判定する
138      set strFilePaht to (POSIX path of itemDropObject) as text
139      set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
140      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
141      set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
142      ###フォルダか?判定
143      set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
144      if (item 3 of listResponse) = (missing value) then
145         log "getResourceValue 正常処理"
146         set ocidURLvalue to (item 2 of listResponse)
147      else if (item 3 of listResponse) ≠ (missing value) then
148         set strErrorNO to (item 2 of listDone)'s code() as text
149         set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
150         refMe's NSLog("■" & strErrorNO & strErrorMes)
151         return "getResourceValue エラーしました" & strErrorNO & strErrorMes
152      end if
153      #フォルダじゃ無いって事は?
154      if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
155         set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
156         if (item 3 of listResponse) = (missing value) then
157            log "getResourceValue 正常処理"
158            #UTIを取得して
159            set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
160         else if (item 3 of listResponse) ≠ (missing value) then
161            set strErrorNO to (item 2 of listDone)'s code() as text
162            set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
163            refMe's NSLog("■" & strErrorNO & strErrorMes)
164            return "getResourceValue エラーしました" & strErrorNO & strErrorMes
165         end if
166         ###getResourceValueの戻り値がNULLだった場合対策
167         if strURLvalue is "" then
168            tell application "Finder"
169               set objInfo to info for aliasFilePath
170               set strURLvalue to type identifier of objInfo as text
171            end tell
172         end if
173         ###UTIPDFのエイリアスだけ処理する
174         if strURLvalue is "com.adobe.pdf" then
175            #####PDFDocumentとして読み込み
176            set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
177            ########################################
178            #暗号化チェック
179            set boolEncrypted to ocidChkDoc's isEncrypted()
180            if boolEncrypted is true then
181               set strName to (name of current application) as text
182               if strName is "osascript" then
183                  tell application "SystemUIServer" to activate
184               else
185                  tell current application to activate
186               end if
187               tell application "SystemUIServer"
188                  activate
189                  set strMes to "エラー:すでに暗号化されているので変更できません" as text
190                  display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
191               end tell
192               tell application "SystemUIServer" to quit
193               refMe's NSLog("■" & strMes)
194               return strMes
195            end if
196            ########################################
197            #ロック確認
198            set boolLocked to ocidChkDoc's isLocked()
199            log boolLocked
200            if boolLocked is true then
201               set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
202               set strName to (name of current application) as text
203               if strName is "osascript" then
204                  tell application "SystemUIServer" to activate
205               else
206                  tell current application to activate
207               end if
208               tell application "SystemUIServer"
209                  activate
210                  display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
211                  refMe's NSLog("■" & strMes)
212               end tell
213               tell application "SystemUIServer" to quit
214               return strMes
215            end if
216            (ocidDropPathURLArray's addObject:(ocidFilePathURL))
217         else
218            set strMes to "エラー:PDF専用です" as text
219            set strName to (name of current application) as text
220            if strName is "osascript" then
221               tell application "SystemUIServer" to activate
222            else
223               tell current application to activate
224            end if
225            tell application "SystemUIServer"
226               activate
227               display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
228            end tell
229            tell application "SystemUIServer" to quit
230            refMe's NSLog("■" & strMes)
231            return strMes
232         end if
233      else
234         set strMes to "エラー:PDF専用です" as text
235         set strName to (name of current application) as text
236         if strName is "osascript" then
237            tell application "SystemUIServer" to activate
238         else
239            tell current application to activate
240         end if
241         tell application "SystemUIServer"
242            activate
243            display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
244         end tell
245         tell application "SystemUIServer" to quit
246         refMe's NSLog("■" & strMes)
247         return strMes
248      end if
249   end repeat
250   ####本処理
251   repeat with itemPathURL in ocidDropPathURLArray
252      set ocidFileName to itemPathURL's lastPathComponent()
253      set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
254      ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
255      set strDirName to (strBaseFileName & "_PW設定済")
256      set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
257      set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
258      set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
259      ####ファイル移動先
260      set appFileManager to refMe's NSFileManager's defaultManager()
261      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s init())
262      (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
263      set listDone to (appFileManager's createDirectoryAtURL:(ocidDistFolderURL) withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
264      if (item 1 of listDone) is true then
265         log "createDirectoryAtURL 正常処理"
266      else if (item 2 of listDone) ≠ (missing value) then
267         set strErrorNO to (item 2 of listDone)'s code() as text
268         set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
269         refMe's NSLog("■:移動でエラー" & strErrorNO & strErrorMes)
270         return "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
271      end if
272      
273      ####コピー
274      set listDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error|:(reference))
275      if (item 1 of listDone) is true then
276         log "copyItemAtURL 正常処理"
277      else if (item 2 of listDone) ≠ (missing value) then
278         set strErrorNO to (item 2 of listDone)'s code() as text
279         set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
280         refMe's NSLog("■:コピーでエラー" & strErrorNO & strErrorMes)
281         return "copyItemAtURL エラーしました" & strErrorNO & strErrorMes
282      end if
283      
284      #####PDFDocumentとして読み込み
285      set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
286      ########################################
287      #パスワード生成 UUIDを利用
288      set strTextFileName to strBaseFileName & ".pw.txt"
289      set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
290      #####生成したUUIDからハイフンを取り除く
291      set ocidUUIDString to (refMe's NSMutableString's alloc()'s init())
292      set ocidConcreteUUID to refMe's NSUUID's UUID()
293      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
294      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
295      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
296      
297      set strOwnerPassword to ocidUUIDString as text
298      ##保存用テキストにする
299      set strTextFile to "所有者用Pw(教えてはいけないヤツ)\n" & strOwnerPassword & "\n" as text
300      if boolOpenPW is true then
301         #####生成したUUIDからハイフンを取り除く
302         set ocidUUIDString to (refMe's NSMutableString's alloc()'s init())
303         set ocidConcreteUUID to refMe's NSUUID's UUID()
304         (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
305         set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
306         (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
307         ##保存用テキストにする
308         set strUserPassword to ocidUUIDString as text
309         set strTextFile to strTextFile & "\n利用者用Pw(他者に教える場合はこちら\n\n\n" as text
310         set strTextFile to strTextFile & "別に送付しましたPDFの開封パスワードです。\nコピペ時には改行が入らないように留意ください\n" as text
311         set strTextFile to strTextFile & "\n" & strUserPassword & "\n" as text
312         
313      end if
314      set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
315      set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
316      ##PWをテキストで保存する
317      set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
318      ########################################
319      #保存OPTION
320      set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s init())
321      if boolOwnerPW = true then
322         (ocidOptionDict's setObject:(strOwnerPassword) forKey:(refMe's PDFDocumentOwnerPasswordOption))
323      end if
324      if boolOpenPW = true then
325         ####開封パスワード
326         (ocidOptionDict's setObject:(strUserPassword) forKey:(refMe's PDFDocumentUserPasswordOption))
327      end if
328      ##############################
329      ###セキュリティ設定
330      ###PDFKitのバグ対策もかねて
331      log intAllowNo
332      #個別の依存でよくある誤りを修正しておく
333      if intAllowNo is 191 then
334         #注釈禁止の場合ドキュメント変更禁止が必要なので追加しておく
335         set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
336      else if intAllowNo is 254 then
337         #低解像度印刷禁止の場合高解像度印刷禁止も必要なので追加しておく
338         set intAllowNo to (intAllowNo - (refMe's PDFAllowsHighQualityPrinting as integer)) as integer
339      else if intAllowNo is 247 then
340         #アッセンブリ禁止の場合はドキュメントに変更も禁止の必要がある
341         set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
342      else if intAllowNo is 127 then
343         #フォーム入力禁止の場合はドキュメントに変更も禁止+注釈禁止の必要がある
344         set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer) - (refMe's PDFAllowsCommenting as integer)) as integer
345      end if
346      log intAllowNo
347      (ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
348      ########################################
349      #保存
350      set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
351   end repeat
352   ########################################
353   #保存先を開く
354   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
355   set boolDone to appSharedWorkspace's openURL:(ocidDistFolderURL)
356   if boolDone is true then
357      log "openURL 正常処理"
358   else if boolDone is false then
359      refMe's NSLog("■:フォルダオープンでエラー")
360      log "openURL エラーしました"
361   end if
362   tell application "SystemUIServer" to quit
363end open
AppleScriptで生成しました

PDFパスワード設定.scpt

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004別名で保存からアプリケーションにすると便利です
005v2 選択内容に依存がある場合の対応をした
006v3 UIの呼び出しを SystemUIServer に変更した
007 com.cocolog-nifty.quicktimer.icefloe *)
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use framework "PDFKit"
013use framework "Quartz"
014use framework "QuartzCore"
015use framework "CoreGraphics"
016use scripting additions
017
018property refMe : a reference to current application
019
020####所有者パスワード
021property boolOwnerPW : true as boolean
022####アクアセス権
023##  property intAllowNo : 0 as integer
024(*
025例:全部OKの場合 255 全部ロックは0
026許可する番号を『足し算』する
027低解像度印刷    (*1*) refMe's PDFAllowsLowQualityPrinting
028高解像度印刷    (*2*) refMe's PDFAllowsHighQualityPrinting
029文書に変更     (*4*) refMe's PDFAllowsDocumentChanges
030アッセンブリ    (*8*) refMe's PDFAllowsDocumentAssembly
031コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
032アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
033コメント注釈    (*64*) refMe's PDFAllowsCommenting
034フォーム入力    (*128*) refMe's PDFAllowsFormFieldEntry
035
036log refMe's PDFAllowsLowQualityPrinting as integer
037log refMe's PDFAllowsHighQualityPrinting as integer
038log refMe's PDFAllowsDocumentChanges as integer
039log refMe's PDFAllowsDocumentAssembly as integer
040log refMe's PDFAllowsContentCopying as integer
041log refMe's PDFAllowsContentAccessibility as integer
042log refMe's PDFAllowsCommenting as integer
043log refMe's PDFAllowsFormFieldEntry as integer
044
045*)
046
047on run
048  ###ダイアログ
049  set strName to (name of current application) as text
050  if strName is "osascript" then
051    tell application "SystemUIServer" to activate
052  else
053    tell current application to activate
054  end if
055  set appFileManager to refMe's NSFileManager's defaultManager()
056  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
057  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
058  set listChooseFileUTI to {"com.adobe.pdf"}
059  set strPromptText to "PDFファイルを選んでください" as text
060  tell application "SystemUIServer"
061    activate
062    set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
063  end tell
064  tell application "SystemUIServer" to quit
065  #選択済みファイルリストをOpenに渡す
066  open listDropObject
067end run
068
069on open listDropObject
070  ##############################
071  set recordOption to {|0開封PW有|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
072  #↑のレコードからキーだけを取り出す
073  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
074  ocidOptionDict's setDictionary:(recordOption)
075  #キーを取り出して
076  set ocidAllKeys to ocidOptionDict's allKeys()
077  #正順に並び替え
078  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
079  #ダイアログ用にArrayをリストにしておく
080  set listAllKeys to ocidSortedArray as list
081  ###ダイアログを前面に出す
082  set strName to (name of current application) as text
083  if strName is "osascript" then
084    tell application "SystemUIServer" to activate
085  else
086    tell current application to activate
087  end if
088  ###
089  set strTitle to "『禁止設定する』オプション選択(複数可)" as text
090  set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンド⌘キーを押しながらクリック\r組み合わせ留意点\r例:\r低解像度印刷の禁止は<高解像度の印刷の禁止に内包されるので無意味な選択になる組み合わせがあります" as text
091  try
092    tell application "SystemUIServer"
093      activate
094      set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
095    end tell
096  on error
097    tell application "SystemUIServer" to quit
098    log "エラーしました"
099    return "エラーしました"
100    error "エラーしました" number -200
101  end try
102  tell application "SystemUIServer" to quit
103  if listResponse = {} then
104    log "何も選択していない"
105    set boolOpenPW to false as boolean
106    set intAllowNo to 0 as integer
107  else if (item 1 of listResponse) is false then
108    return "キャンセルしました"
109    error "キャンセルしました" number -200
110  else
111    set boolOpenPW to false as boolean
112    set intAllowNo to 0 as integer
113    repeat with itemResponse in listResponse
114      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
115      #戻り値が999ならOPEN時のパスワード設定をする
116      if intValue = 999 then
117        set boolOpenPW to true as boolean
118      else
119        set intAllowNo to intAllowNo + intValue
120      end if
121    end repeat
122  end if
123  ##許可番号
124  set intAllowNo to (255 - intAllowNo) as integer
125
126  ########################################
127  #実際の処理するPDFのURLを格納するリスト
128  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
129  ###ドロップされたエイリアスの数だけ繰り返し
130  repeat with itemDropObject in listDropObject
131    ###処理除外するエイリアスを判定する
132    set strFilePaht to (POSIX path of itemDropObject) as text
133    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
134    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
135    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
136    ###フォルダか?判定
137    set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
138    if (item 3 of listResponse) = (missing value) then
139      log "getResourceValue 正常処理"
140      set ocidURLvalue to (item 2 of listResponse)
141    else if (item 3 of listResponse) (missing value) then
142      set strErrorNO to (item 2 of listDone)'s code() as text
143      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
144      refMe's NSLog("■:" & strErrorNO & strErrorMes)
145      return "getResourceValue エラーしました" & strErrorNO & strErrorMes
146    end if
147    #フォルダじゃ無いって事は?
148    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
149      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
150      if (item 3 of listResponse) = (missing value) then
151        log "getResourceValue 正常処理"
152        #UTIを取得して
153        set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
154      else if (item 3 of listResponse) (missing value) then
155        set strErrorNO to (item 2 of listDone)'s code() as text
156        set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
157        refMe's NSLog("■:" & strErrorNO & strErrorMes)
158        return "getResourceValue エラーしました" & strErrorNO & strErrorMes
159      end if
160      ###getResourceValueの戻り値がNULLだった場合対策
161      if strURLvalue is "" then
162        tell application "Finder"
163          set objInfo to info for aliasFilePath
164          set strURLvalue to type identifier of objInfo as text
165        end tell
166      end if
167      ###UTIがPDFのエイリアスだけ処理する
168      if strURLvalue is "com.adobe.pdf" then
169        #####PDFDocumentとして読み込み
170        set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
171        ########################################
172        #暗号化チェック
173        set boolEncrypted to ocidChkDoc's isEncrypted()
174        if boolEncrypted is true then
175          set strName to (name of current application) as text
176          if strName is "osascript" then
177            tell application "SystemUIServer" to activate
178          else
179            tell current application to activate
180          end if
181          tell application "SystemUIServer"
182            activate
183            set strMes to "エラー:すでに暗号化されているので変更できません" as text
184            display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
185          end tell
186          tell application "SystemUIServer" to quit
187          refMe's NSLog("■:" & strMes)
188          return strMes
189        end if
190        ########################################
191        #ロック確認
192        set boolLocked to ocidChkDoc's isLocked()
193        log boolLocked
194        if boolLocked is true then
195          set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
196          set strName to (name of current application) as text
197          if strName is "osascript" then
198            tell application "SystemUIServer" to activate
199          else
200            tell current application to activate
201          end if
202          tell application "SystemUIServer"
203            activate
204            display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
205            refMe's NSLog("■:" & strMes)
206          end tell
207          tell application "SystemUIServer" to quit
208          return strMes
209        end if
210        (ocidDropPathURLArray's addObject:(ocidFilePathURL))
211      else
212        set strMes to "エラー:PDF専用です" as text
213        set strName to (name of current application) as text
214        if strName is "osascript" then
215          tell application "SystemUIServer" to activate
216        else
217          tell current application to activate
218        end if
219        tell application "SystemUIServer"
220          activate
221          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
222        end tell
223        tell application "SystemUIServer" to quit
224        refMe's NSLog("■:" & strMes)
225        return strMes
226      end if
227    else
228      set strMes to "エラー:PDF専用です" as text
229      set strName to (name of current application) as text
230      if strName is "osascript" then
231        tell application "SystemUIServer" to activate
232      else
233        tell current application to activate
234      end if
235      tell application "SystemUIServer"
236        activate
237        display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
238      end tell
239      tell application "SystemUIServer" to quit
240      refMe's NSLog("■:" & strMes)
241      return strMes
242    end if
243  end repeat
244  ####本処理
245  repeat with itemPathURL in ocidDropPathURLArray
246    set ocidFileName to itemPathURL's lastPathComponent()
247    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
248    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
249    set strDirName to (strBaseFileName & "_PW設定済")
250    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
251    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
252    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
253    ####ファイル移動先
254    set appFileManager to refMe's NSFileManager's defaultManager()
255    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
256    (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
257    set listDone to (appFileManager's createDirectoryAtURL:(ocidDistFolderURL) withIntermediateDirectories:true attributes:ocidAttrDict  |error| :(reference))
258    if (item 1 of listDone) is true then
259      log "createDirectoryAtURL 正常処理"
260    else if (item 2 of listDone) (missing value) then
261      set strErrorNO to (item 2 of listDone)'s code() as text
262      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
263      refMe's NSLog("■:移動でエラー" & strErrorNO & strErrorMes)
264      return "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
265    end if
266
267    ####コピー
268    set listDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error| :(reference))
269    if (item 1 of listDone) is true then
270      log "copyItemAtURL 正常処理"
271    else if (item 2 of listDone) (missing value) then
272      set strErrorNO to (item 2 of listDone)'s code() as text
273      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
274      refMe's NSLog("■:コピーでエラー" & strErrorNO & strErrorMes)
275      return "copyItemAtURL エラーしました" & strErrorNO & strErrorMes
276    end if
277
278    #####PDFDocumentとして読み込み
279    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
280    ########################################
281    #パスワード生成 UUIDを利用
282    set strTextFileName to strBaseFileName & ".pw.txt"
283    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
284    #####生成したUUIDからハイフンを取り除く
285    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
286    set ocidConcreteUUID to refMe's NSUUID's UUID()
287    (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
288    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
289    (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
290
291    set strOwnerPassword to ocidUUIDString as text
292    ##保存用テキストにする
293    set strTextFile to "所有者用Pw(教えてはいけないヤツ)\n" & strOwnerPassword & "\n" as text
294    if boolOpenPW is true then
295      #####生成したUUIDからハイフンを取り除く
296      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
297      set ocidConcreteUUID to refMe's NSUUID's UUID()
298      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
299      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
300      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
301      ##保存用テキストにする
302      set strUserPassword to ocidUUIDString as text
303      set strTextFile to strTextFile & "\n利用者用Pw(他者に教える場合はこちら↓)\n\n\n" as text
304      set strTextFile to strTextFile & "別に送付しましたPDFの開封パスワードです。\nコピペ時には改行が入らないように留意ください\n" as text
305      set strTextFile to strTextFile & "\n" & strUserPassword & "\n" as text
306
307    end if
308    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
309    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
310    ##PWをテキストで保存する
311    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
312    ########################################
313    #保存OPTION
314    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
315    if boolOwnerPW = true then
316      (ocidOptionDict's setObject:(strOwnerPassword) forKey:(refMe's PDFDocumentOwnerPasswordOption))
317    end if
318    if boolOpenPW = true then
319      ####開封パスワード
320      (ocidOptionDict's setObject:(strUserPassword) forKey:(refMe's PDFDocumentUserPasswordOption))
321    end if
322    ##############################
323    ###セキュリティ設定
324    ###PDFKitのバグ対策もかねて
325    log intAllowNo
326    #個別の依存でよくある誤りを修正しておく
327    if intAllowNo is 191 then
328      #注釈禁止の場合ドキュメント変更禁止が必要なので追加しておく
329      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
330    else if intAllowNo is 254 then
331      #低解像度印刷禁止の場合高解像度印刷禁止も必要なので追加しておく
332      set intAllowNo to (intAllowNo - (refMe's PDFAllowsHighQualityPrinting as integer)) as integer
333    else if intAllowNo is 247 then
334      #アッセンブリ禁止の場合はドキュメントに変更も禁止の必要がある
335      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
336    else if intAllowNo is 127 then
337      #フォーム入力禁止の場合はドキュメントに変更も禁止+注釈禁止の必要がある
338      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer) - (refMe's PDFAllowsCommenting as integer)) as integer
339    end if
340    log intAllowNo
341    (ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
342    ########################################
343    #保存
344    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
345  end repeat
346  ########################################
347  #保存先を開く
348  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
349  set boolDone to appSharedWorkspace's openURL:(ocidDistFolderURL)
350  if boolDone is true then
351    log "openURL 正常処理"
352  else if boolDone is false then
353    refMe's NSLog("■:フォルダオープンでエラー")
354    log "openURL エラーしました"
355  end if
356
357end open
AppleScriptで生成しました

|

PDFパスワード設定(ドロップレット)少し工夫した



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions




ダウンロード - setpdfpermissions.zip




AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# com.cocolog-nifty.quicktimer.icefloe
004#別名で保存からアプリケーションにすると便利です
005#
006#選択内容に依存がある場合の対応をした
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use framework "PDFKit"
012use framework "Quartz"
013use framework "QuartzCore"
014use framework "CoreGraphics"
015use scripting additions
016
017property refMe : a reference to current application
018
019####所有者パスワード
020property boolOwnerPW : true as boolean
021####アクアセス権
022##  property intAllowNo : 0 as integer
023(*
024例:全部OKの場合 255 全部ロックは0
025許可する番号を『足し算』する
026低解像度印刷    (*1*) refMe's PDFAllowsLowQualityPrinting
027高解像度印刷    (*2*) refMe's PDFAllowsHighQualityPrinting
028文書に変更     (*4*) refMe's PDFAllowsDocumentChanges
029アッセンブリ    (*8*) refMe's PDFAllowsDocumentAssembly
030コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
031アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
032コメント注釈    (*64*) refMe's PDFAllowsCommenting
033フォーム入力    (*128*) refMe's PDFAllowsFormFieldEntry
034
035log refMe's PDFAllowsLowQualityPrinting as integer
036log refMe's PDFAllowsHighQualityPrinting as integer
037log refMe's PDFAllowsDocumentChanges as integer
038log refMe's PDFAllowsDocumentAssembly as integer
039log refMe's PDFAllowsContentCopying as integer
040log refMe's PDFAllowsContentAccessibility as integer
041log refMe's PDFAllowsCommenting as integer
042log refMe's PDFAllowsFormFieldEntry as integer
043
044*)
045
046on run
047  ###ダイアログを前面に出す
048  tell current application
049    set strName to name as text
050  end tell
051  if strName is "osascript" then
052    tell application "Finder" to activate
053  else
054    tell current application to activate
055  end if
056  set appFileManager to refMe's NSFileManager's defaultManager()
057  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
058  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
059  set listChooseFileUTI to {"com.adobe.pdf"}
060  set strPromptText to "PDFファイルを選んでください" as text
061  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
062  #選択済みファイルリストをOpenに渡す
063  open listDropObject
064end run
065
066on open listDropObject
067  ##############################
068  set recordOption to {|0開封PW有|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
069  #↑のレコードからキーだけを取り出す
070  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
071  ocidOptionDict's setDictionary:(recordOption)
072  #キーを取り出して
073  set ocidAllKeys to ocidOptionDict's allKeys()
074  #正順に並び替え
075  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
076  #ダイアログ用にArrayをリストにしておく
077  set listAllKeys to ocidSortedArray as list
078  ###ダイアログを前面に出す
079  tell current application
080    set strName to name as text
081  end tell
082  if strName is "osascript" then
083    tell application "Finder" to activate
084  else
085    tell current application to activate
086  end if
087  ###
088  set strTitle to "『禁止設定する』オプション選択(複数可)" as text
089  set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンド⌘キーを押しながらクリック\r組み合わせ留意点\r例:\r低解像度印刷の禁止は<高解像度の印刷の禁止に内包されるので無意味な選択になる組み合わせがあります" as text
090  try
091    set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
092  on error
093    log "エラーしました"
094    return "エラーしました"
095    error "エラーしました" number -200
096  end try
097  if listResponse = {} then
098    log "何も選択していない"
099    set boolOpenPW to false as boolean
100    set intAllowNo to 0 as integer
101  else if (item 1 of listResponse) is false then
102    return "キャンセルしました"
103    error "キャンセルしました" number -200
104  else
105    set boolOpenPW to false as boolean
106    set intAllowNo to 0 as integer
107    repeat with itemResponse in listResponse
108      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
109      #戻り値が999ならOPEN時のパスワード設定をする
110      if intValue = 999 then
111        set boolOpenPW to true as boolean
112      else
113        set intAllowNo to intAllowNo + intValue
114      end if
115    end repeat
116  end if
117  ##許可番号
118  set intAllowNo to (255 - intAllowNo) as integer
119  
120  ########################################
121  #実際の処理するPDFのURLを格納するリスト
122  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
123  ###ドロップされたエイリアスの数だけ繰り返し
124  repeat with itemDropObject in listDropObject
125    ###処理除外するエイリアスを判定する
126    set strFilePaht to (POSIX path of itemDropObject) as text
127    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
128    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
129    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
130    ###フォルダか?判定
131    set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
132    if (item 3 of listResponse) = (missing value) then
133      log "正常処理"
134      set ocidURLvalue to (item 2 of listResponse)
135    else if (item 3 of listResponse) ≠ (missing value) then
136      set strErrorNO to (item 2 of listDone)'s code() as text
137      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
138      refMe's NSLog("■:" & strErrorNO & strErrorMes)
139      return "エラーしました" & strErrorNO & strErrorMes
140    end if
141    #フォルダじゃ無いって事は?
142    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
143      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
144      if (item 3 of listResponse) = (missing value) then
145        log "正常処理"
146        #UTIを取得して
147        set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
148      else if (item 3 of listResponse) ≠ (missing value) then
149        set strErrorNO to (item 2 of listDone)'s code() as text
150        set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
151        refMe's NSLog("■:" & strErrorNO & strErrorMes)
152        return "エラーしました" & strErrorNO & strErrorMes
153      end if
154      ###getResourceValueの戻り値がNULLだった場合対策
155      if strURLvalue is "" then
156        tell application "Finder"
157          set objInfo to info for aliasFilePath
158          set strURLvalue to type identifier of objInfo as text
159        end tell
160      end if
161      ###UTIがPDFのエイリアスだけ処理する
162      if strURLvalue is "com.adobe.pdf" then
163        #####PDFDocumentとして読み込み
164        set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
165        ########################################
166        #暗号化チェック
167        set boolEncrypted to ocidChkDoc's isEncrypted()
168        if boolEncrypted is true then
169          set strMes to "エラー:すでに暗号化されているので変更できません" as text
170          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
171          refMe's NSLog("■:" & strMes)
172          return strMes
173        end if
174        ########################################
175        #ロック確認
176        set boolLocked to ocidChkDoc's isLocked()
177        log boolEncrypted
178        if boolLocked is true then
179          set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
180          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
181          refMe's NSLog("■:" & strMes)
182          return strMes
183        end if
184        (ocidDropPathURLArray's addObject:(ocidFilePathURL))
185      else
186        set strMes to "エラー:PDF専用です" as text
187        display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
188        refMe's NSLog("■:" & strMes)
189        return strMes
190      end if
191    else
192      set strMes to "エラー:PDF専用です" as text
193      display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
194      refMe's NSLog("■:" & strMes)
195      return strMes
196    end if
197  end repeat
198  ####本処理
199  repeat with itemPathURL in ocidDropPathURLArray
200    set ocidFileName to itemPathURL's lastPathComponent()
201    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
202    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
203    set strDirName to (strBaseFileName & "_PW設定済")
204    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
205    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
206    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
207    ####ファイル移動先
208    set appFileManager to refMe's NSFileManager's defaultManager()
209    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
210    (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
211    set listDone to (appFileManager's createDirectoryAtURL:(ocidDistFolderURL) withIntermediateDirectories:true attributes:ocidAttrDict  |error| :(reference))
212    if (item 1 of listDone) is true then
213      log "正常処理"
214    else if (item 2 of listDone) ≠ (missing value) then
215      set strErrorNO to (item 2 of listDone)'s code() as text
216      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
217      refMe's NSLog("■:移動でエラー" & strErrorNO & strErrorMes)
218      return "エラーしました" & strErrorNO & strErrorMes
219    end if
220    
221    ####コピー
222    set listDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error| :(reference))
223    if (item 1 of listDone) is true then
224      log "正常処理"
225    else if (item 2 of listDone) ≠ (missing value) then
226      set strErrorNO to (item 2 of listDone)'s code() as text
227      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
228      refMe's NSLog("■:コピーでエラー" & strErrorNO & strErrorMes)
229      return "エラーしました" & strErrorNO & strErrorMes
230    end if
231    
232    #####PDFDocumentとして読み込み
233    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
234    ########################################
235    #パスワード生成 UUIDを利用
236    set strTextFileName to strBaseFileName & ".pw.txt"
237    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
238    #####生成したUUIDからハイフンを取り除く
239    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
240    set ocidConcreteUUID to refMe's NSUUID's UUID()
241    (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
242    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
243    (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
244    
245    set strOwnerPassword to ocidUUIDString as text
246    ##保存用テキストにする
247    set strTextFile to "所有者用Pw(教えてはいけないヤツ)\n" & strOwnerPassword & "\n" as text
248    if boolOpenPW is true then
249      #####生成したUUIDからハイフンを取り除く
250      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
251      set ocidConcreteUUID to refMe's NSUUID's UUID()
252      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
253      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
254      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
255      ##保存用テキストにする
256      set strUserPassword to ocidUUIDString as text
257      set strTextFile to strTextFile & "\n利用者用Pw(他者に教える場合はこちら↓)\n\n\n" as text
258      set strTextFile to strTextFile & "別に送付しましたPDFの開封パスワードです。\nコピペ時には改行が入らないように留意ください\n" as text
259      set strTextFile to strTextFile & "\n" & strUserPassword & "\n" as text
260      
261    end if
262    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
263    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
264    ##PWをテキストで保存する
265    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
266    ########################################
267    #保存OPTION
268    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
269    if boolOwnerPW = true then
270      (ocidOptionDict's setObject:(strOwnerPassword) forKey:(refMe's PDFDocumentOwnerPasswordOption))
271    end if
272    if boolOpenPW = true then
273      ####開封パスワード
274      (ocidOptionDict's setObject:(strUserPassword) forKey:(refMe's PDFDocumentUserPasswordOption))
275    end if
276    ##############################
277    ###セキュリティ設定
278    ###PDFKitのバグ対策もかねて
279    log intAllowNo
280    #個別の依存でよくある誤りを修正しておく
281    if intAllowNo is 191 then
282      #注釈禁止の場合ドキュメント変更禁止が必要なので追加しておく
283      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
284    else if intAllowNo is 254 then
285      #低解像度印刷禁止の場合高解像度印刷禁止も必要なので追加しておく
286      set intAllowNo to (intAllowNo - (refMe's PDFAllowsHighQualityPrinting as integer)) as integer
287    else if intAllowNo is 247 then
288      #アッセンブリ禁止の場合はドキュメントに変更も禁止の必要がある
289      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer)) as integer
290    else if intAllowNo is 127 then
291      #フォーム入力禁止の場合はドキュメントに変更も禁止+注釈禁止の必要がある
292      set intAllowNo to (intAllowNo - (refMe's PDFAllowsDocumentChanges as integer) - (refMe's PDFAllowsCommenting as integer)) as integer
293    end if
294    log intAllowNo
295    (ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
296    ########################################
297    #保存
298    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
299  end repeat
300  ########################################
301  #保存先を開く
302  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
303  set boolDone to appSharedWorkspace's openURL:(ocidDistFolderURL)
304  if boolDone is true then
305    log "正常処理"
306  else if boolDone is false then
307    refMe's NSLog("■:フォルダオープンでエラー")
308    log "エラーしました"
309  end if
310  
311end open
AppleScriptで生成しました

|

[PDFKit]PDFにアクセス権を付与する(エラー制御を追加)



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# com.cocolog-nifty.quicktimer.icefloe
004# ドロップレットとして利用できるようにしてあります
005# 別名で保存からアプリケーションにすると便利です
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use framework "PDFKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015####所有者パスワード
016property boolOwnerPW : true as boolean
017####アクアセス権
018##  property intAllowNo : 0 as integer
019(*
020例:全部OKの場合 255 全部ロックは0
021許可する番号を『足し算』する
022低解像度印刷    (*1*) PDFAllowsLowQualityPrinting
023高解像度印刷    (*2*) refMe's PDFAllowsHighQualityPrinting
024文書に変更     (*4*) refMe's PDFAllowsDocumentChanges
025アッセンブリ    (*8*) refMe's PDFAllowsDocumentAssembly
026コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
027アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
028コメント注釈    (*64*) refMe's PDFAllowsCommenting
029フォーム入力    (*128*) refMe's PDFAllowsFormFieldEntry
030*)
031
032on run
033  ###ダイアログを前面に出す
034  tell current application
035    set strName to name as text
036  end tell
037  ####スクリプトメニューから実行したら
038  if strName is "osascript" then
039    tell application "Finder" to activate
040  else
041    tell current application to activate
042  end if
043  set appFileManager to refMe's NSFileManager's defaultManager()
044  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
045  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
046  set listChooseFileUTI to {"com.adobe.pdf"}
047  set strPromptText to "PDFファイルを選んでください" as text
048  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
049  open listDropObject
050end run
051
052on open listDropObject
053  
054  set recordOption to {|0開封PW有|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
055  
056  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
057  ocidOptionDict's setDictionary:(recordOption)
058  set ocidAllKeys to ocidOptionDict's allKeys()
059  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
060  set listAllKeys to ocidSortedArray as list
061  
062  ##############################
063  ###ダイアログを前面に出す
064  tell current application
065    set strName to name as text
066  end tell
067  ###スクリプトメニューから実行したら
068  if strName is "osascript" then
069    tell application "Finder" to activate
070  else
071    tell current application to activate
072  end if
073  ###
074  set strTitle to "『禁止設定する』オプション選択(複数可)" as text
075  set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンド⌘キーを押しながらクリック" as text
076  try
077    set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
078  on error
079    log "エラーしました"
080    return "エラーしました"
081    error "エラーしました" number -200
082  end try
083  if listResponse = {} then
084    log "何も選択していない"
085    set boolOpenPW to false as boolean
086    set intAllowNo to 0 as integer
087  else if (item 1 of listResponse) is false then
088    return "キャンセルしました"
089    error "キャンセルしました" number -200
090  else
091    set boolOpenPW to false as boolean
092    set intAllowNo to 0 as integer
093    repeat with itemResponse in listResponse
094      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
095      if intValue = 999 then
096        set boolOpenPW to true as boolean
097      else
098        set intAllowNo to intAllowNo + intValue
099      end if
100    end repeat
101  end if
102  
103  set intAllowNo to (255 - intAllowNo) as integer
104  
105  ########################################
106  #実際の処理するPDFのURLを格納するリスト
107  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
108  ###ドロップされたエイリアスの数だけ繰り返し
109  repeat with itemDropObject in listDropObject
110    ###処理除外するエイリアスを判定する
111    set strFilePaht to (POSIX path of itemDropObject) as text
112    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
113    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
114    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
115    ###フォルダか?判定
116    set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
117    if (item 3 of listResponse) = (missing value) then
118      log "正常処理"
119      set ocidURLvalue to (item 2 of listResponse)
120    else if (item 3 of listResponse) ≠ (missing value) then
121      set strErrorNO to (item 2 of listDone)'s code() as text
122      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
123      refMe's NSLog("■:" & strErrorNO & strErrorMes)
124      return "エラーしました" & strErrorNO & strErrorMes
125    end if
126    #フォルダじゃ無いって事は?
127    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
128      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
129      if (item 3 of listResponse) = (missing value) then
130        log "正常処理"
131        #UTIを取得して
132        set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
133      else if (item 3 of listResponse) ≠ (missing value) then
134        set strErrorNO to (item 2 of listDone)'s code() as text
135        set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
136        refMe's NSLog("■:" & strErrorNO & strErrorMes)
137        return "エラーしました" & strErrorNO & strErrorMes
138      end if
139      ###getResourceValueの戻り値がNULLだった場合対策
140      if strURLvalue is "" then
141        tell application "Finder"
142          set objInfo to info for aliasFilePath
143          set strURLvalue to type identifier of objInfo as text
144        end tell
145      end if
146      ###UTIがPDFのエイリアスだけ処理する
147      if strURLvalue is "com.adobe.pdf" then
148        #####PDFDocumentとして読み込み
149        set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
150        ########################################
151        #暗号化チェック
152        set boolEncrypted to ocidChkDoc's isEncrypted()
153        if boolEncrypted is true then
154          set strMes to "エラー:すでに暗号化されているので変更できません" as text
155          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
156          refMe's NSLog("■:" & strMes)
157          return strMes
158        end if
159        ########################################
160        #ロック確認
161        set boolLocked to ocidChkDoc's isLocked()
162        log boolEncrypted
163        if boolLocked is true then
164          set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
165          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
166          refMe's NSLog("■:" & strMes)
167          return strMes
168        end if
169        (ocidDropPathURLArray's addObject:(ocidFilePathURL))
170      else
171        set strMes to "エラー:PDF専用です" as text
172        display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
173        refMe's NSLog("■:" & strMes)
174        return strMes
175      end if
176    else
177      set strMes to "エラー:PDF専用です" as text
178      display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
179      refMe's NSLog("■:" & strMes)
180      return strMes
181    end if
182  end repeat
183  
184  repeat with itemPathURL in ocidDropPathURLArray
185    set ocidFileName to itemPathURL's lastPathComponent()
186    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
187    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
188    set strDirName to (strBaseFileName & "_PW設定済")
189    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
190    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
191    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
192    ####ファイル移動先
193    set appFileManager to refMe's NSFileManager's defaultManager()
194    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
195    (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
196    set listDone to (appFileManager's createDirectoryAtURL:(ocidDistFolderURL) withIntermediateDirectories:true attributes:ocidAttrDict  |error| :(reference))
197    if (item 1 of listDone) is true then
198      log "正常処理"
199    else if (item 2 of listDone) ≠ (missing value) then
200      set strErrorNO to (item 2 of listDone)'s code() as text
201      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
202      refMe's NSLog("■:移動でエラー" & strErrorNO & strErrorMes)
203      return "エラーしました" & strErrorNO & strErrorMes
204    end if
205    
206    ####コピー
207    set listDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error| :(reference))
208    if (item 1 of listDone) is true then
209      log "正常処理"
210    else if (item 2 of listDone) ≠ (missing value) then
211      set strErrorNO to (item 2 of listDone)'s code() as text
212      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
213      refMe's NSLog("■:コピーでエラー" & strErrorNO & strErrorMes)
214      return "エラーしました" & strErrorNO & strErrorMes
215    end if
216    
217    #####PDFDocumentとして読み込み
218    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
219    ########################################
220    #パスワード生成 UUIDを利用
221    set strTextFileName to strBaseFileName & ".pw.txt"
222    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
223    #####生成したUUIDからハイフンを取り除く
224    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
225    set ocidConcreteUUID to refMe's NSUUID's UUID()
226    (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
227    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
228    (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
229    
230    set strOwnerPassword to ocidUUIDString as text
231    ##保存用テキストにする
232    set strTextFile to "所有者用Pw(教えてはいけないヤツ)\n" & strOwnerPassword & "\n" as text
233    if boolOpenPW is true then
234      #####生成したUUIDからハイフンを取り除く
235      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
236      set ocidConcreteUUID to refMe's NSUUID's UUID()
237      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
238      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
239      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
240      ##保存用テキストにする
241      set strUserPassword to ocidUUIDString as text
242      set strTextFile to strTextFile & "\n利用者用Pw(他者に教える場合はこちら↓)\n" as text
243      set strTextFile to strTextFile & "別に送付しましたPDFの開封パスワードです。\nコピペ時には改行が入らないように留意ください\n" as text
244      set strTextFile to strTextFile & "\n" & strUserPassword & "\n" as text
245      
246    end if
247    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
248    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
249    ##PWをテキストで保存する
250    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
251    ########################################
252    #保存OPTION
253    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
254    if boolOwnerPW = true then
255      (ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
256    end if
257    if boolOpenPW = true then
258      ####開封パスワード
259      (ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
260    end if
261    ###セキュリティ設定
262    (ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
263    ########################################
264    #保存
265    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
266  end repeat
267  ########################################
268  #保存先を開く
269  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
270  set boolDone to appSharedWorkspace's openURL:(ocidDistFolderURL)
271  if boolDone is true then
272    log "正常処理"
273  else if boolDone is false then
274    refMe's NSLog("■:フォルダオープンでエラー")
275    log "エラーしました"
276  end if
277  
278end open
AppleScriptで生成しました

|

PDFに権限パスワードを設定する(エラー制御を少し修正)



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# com.cocolog-nifty.quicktimer.icefloe
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use framework "AppKit"
008use framework "PDFKit"
009use framework "Quartz"
010use framework "QuartzCore"
011use framework "CoreGraphics"
012use scripting additions
013
014property refMe : a reference to current application
015
016####所有者パスワード
017property boolOwnerPW : true as boolean
018####アクアセス権
019##  property intAllowNo : 0 as integer
020(*
021例:全部OKの場合 255 全部ロックは0
022許可する番号を『足し算』する
023低解像度印刷    (*1*) PDFAllowsLowQualityPrinting
024高解像度印刷    (*2*) refMe's PDFAllowsHighQualityPrinting
025文書に変更     (*4*) refMe's PDFAllowsDocumentChanges
026アッセンブリ    (*8*) refMe's PDFAllowsDocumentAssembly
027コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
028アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
029コメント注釈    (*64*) refMe's PDFAllowsCommenting
030フォーム入力    (*128*) refMe's PDFAllowsFormFieldEntry
031*)
032
033on run
034  ###ダイアログを前面に出す
035  tell current application
036    set strName to name as text
037  end tell
038  ####スクリプトメニューから実行したら
039  if strName is "osascript" then
040    tell application "Finder" to activate
041  else
042    tell current application to activate
043  end if
044  set appFileManager to refMe's NSFileManager's defaultManager()
045  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
046  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
047  set listChooseFileUTI to {"com.adobe.pdf"}
048  set strPromptText to "PDFファイルを選んでください" as text
049  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
050  open listDropObject
051end run
052
053on open listDropObject
054  
055  set recordOption to {|0開封PW有|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
056  
057  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
058  ocidOptionDict's setDictionary:(recordOption)
059  set ocidAllKeys to ocidOptionDict's allKeys()
060  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
061  set listAllKeys to ocidSortedArray as list
062  
063  ##############################
064  ###ダイアログを前面に出す
065  tell current application
066    set strName to name as text
067  end tell
068  ###スクリプトメニューから実行したら
069  if strName is "osascript" then
070    tell application "Finder" to activate
071  else
072    tell current application to activate
073  end if
074  ###
075  set strTitle to "『禁止設定する』オプション選択(複数可)" as text
076  set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンド⌘キーを押しながらクリック" as text
077  try
078    set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
079  on error
080    log "エラーしました"
081    return "エラーしました"
082    error "エラーしました" number -200
083  end try
084  if listResponse = {} then
085    log "何も選択していない"
086    set boolOpenPW to false as boolean
087    set intAllowNo to 0 as integer
088  else if (item 1 of listResponse) is false then
089    return "キャンセルしました"
090    error "キャンセルしました" number -200
091  else
092    set boolOpenPW to false as boolean
093    set intAllowNo to 0 as integer
094    repeat with itemResponse in listResponse
095      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
096      if intValue = 999 then
097        set boolOpenPW to true as boolean
098      else
099        set intAllowNo to intAllowNo + intValue
100      end if
101    end repeat
102  end if
103  
104  set intAllowNo to (255 - intAllowNo) as integer
105  
106  ###############################
107  ##実際の処理するPDFのURLを格納するリスト
108  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
109  ###ドロップされたエイリアスの数だけ繰り返し
110  repeat with itemDropObject in listDropObject
111    ###処理除外するエイリアスを判定する
112    set strFilePaht to (POSIX path of itemDropObject) as text
113    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
114    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
115    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
116    ###フォルダか?判定
117    set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
118    if (item 3 of listResponse) = (missing value) then
119      log "正常処理"
120      set ocidURLvalue to (item 2 of listResponse)
121    else if (item 3 of listResponse) ≠ (missing value) then
122      set strErrorNO to (item 2 of listDone)'s code() as text
123      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
124      refMe's NSLog("■:" & strErrorNO & strErrorMes)
125      return "エラーしました" & strErrorNO & strErrorMes
126    end if
127    #フォルダじゃ無いって事は?
128    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
129      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
130      if (item 3 of listResponse) = (missing value) then
131        log "正常処理"
132        #UTIを取得して
133        set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
134      else if (item 3 of listResponse) ≠ (missing value) then
135        set strErrorNO to (item 2 of listDone)'s code() as text
136        set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
137        refMe's NSLog("■:" & strErrorNO & strErrorMes)
138        return "エラーしました" & strErrorNO & strErrorMes
139      end if
140      ###getResourceValueの戻り値がNULLだった場合対策
141      if strURLvalue is "" then
142        tell application "Finder"
143          set objInfo to info for aliasFilePath
144          set strURLvalue to type identifier of objInfo as text
145        end tell
146      end if
147      ###UTIがPDFのエイリアスだけ処理する
148      if strURLvalue is "com.adobe.pdf" then
149        #####PDFDocumentとして読み込み
150        set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
151        ########################################
152        #####暗号化チェック
153        set boolEncrypted to ocidChkDoc's isEncrypted()
154        if boolEncrypted is true then
155          set strMes to "エラー:すでに暗号化されているので変更できません" as text
156          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
157          refMe's NSLog("■:" & strMes)
158          return strMes
159        end if
160        ########################################
161        #####ロック確認
162        set boolLocked to ocidChkDoc's isLocked()
163        log boolEncrypted
164        if boolLocked is true then
165          set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
166          display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
167          refMe's NSLog("■:" & strMes)
168          return strMes
169        end if
170        (ocidDropPathURLArray's addObject:(ocidFilePathURL))
171      else
172        set strMes to "エラー:PDF専用です" as text
173        display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
174        refMe's NSLog("■:" & strMes)
175        return strMes
176      end if
177    else
178      set strMes to "エラー:PDF専用です" as text
179      display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
180      refMe's NSLog("■:" & strMes)
181      return strMes
182    end if
183  end repeat
184  
185  repeat with itemPathURL in ocidDropPathURLArray
186    set ocidFileName to itemPathURL's lastPathComponent()
187    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
188    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
189    set strDirName to (strBaseFileName & "_PW設定済")
190    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
191    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
192    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
193    ####ファイル移動先
194    set appFileManager to refMe's NSFileManager's defaultManager()
195    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
196    (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
197    set listDone to (appFileManager's createDirectoryAtURL:ocidDistFolderURL withIntermediateDirectories:true attributes:ocidAttrDict  |error| :(reference))
198    if (item 1 of listDone) is true then
199      log "正常処理"
200    else if (item 2 of listDone) ≠ (missing value) then
201      set strErrorNO to (item 2 of listDone)'s code() as text
202      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
203      refMe's NSLog("■:" & strErrorNO & strErrorMes)
204      return "エラーしました" & strErrorNO & strErrorMes
205    end if
206    
207    ####コピー
208    set listDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error| :(reference))
209    if (item 1 of listDone) is true then
210      log "正常処理"
211    else if (item 2 of listDone) ≠ (missing value) then
212      set strErrorNO to (item 2 of listDone)'s code() as text
213      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
214      refMe's NSLog("■:" & strErrorNO & strErrorMes)
215      return "エラーしました" & strErrorNO & strErrorMes
216    end if
217    
218    #####PDFDocumentとして読み込み
219    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
220    ########################################
221    #####パスワード生成 UUIDを利用
222    set strTextFileName to strBaseFileName & ".pw.txt"
223    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
224    #####生成したUUIDからハイフンを取り除く
225    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
226    set ocidConcreteUUID to refMe's NSUUID's UUID()
227    (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
228    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
229    (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
230    
231    
232    set strOwnerPassword to ocidUUIDString as text
233    ##保存用テキストにする
234    set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n" as text
235    if boolOpenPW is true then
236      #####生成したUUIDからハイフンを取り除く
237      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
238      set ocidConcreteUUID to refMe's NSUUID's UUID()
239      (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
240      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
241      (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
242      ##保存用テキストにする
243      set strUserPassword to ocidUUIDString as text
244      set strTextFile to strTextFile & "利用者用Pw(他者に教える場合はこちら↓)\n" & strUserPassword & "\n" as text
245    end if
246    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
247    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
248    ##PWをテキストで保存する
249    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
250    ########################################
251    #####保存OPTION
252    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
253    if boolOwnerPW = true then
254      (ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
255    end if
256    if boolOpenPW = true then
257      ####開封パスワード
258      (ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
259    end if
260    ###セキュリティ設定
261    (ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
262    ##################
263    ###保存
264    ##################
265    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
266  end repeat
267end open
AppleScriptで生成しました

|

[PDFKit]暗号化 機能制限パスワードを設定する



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


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

#!/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 "PDFKit"
use framework "Quartz"
use framework "QuartzCore"
use framework "CoreGraphics"
use scripting additions

property refMe : a reference to current application

####所有者パスワード
property boolOwnerPW : true as boolean
####アクアセス権
## property intAllowNo : 0 as integer
(*
例:全部OKの場合 255 全部ロックは0
許可する番号を『足し算』する
低解像度印刷 (*1*) PDFAllowsLowQualityPrinting
高解像度印刷 (*2*) refMe's PDFAllowsHighQualityPrinting
文書に変更 (*4*) refMe's PDFAllowsDocumentChanges
アッセンブリ (*8*) refMe's PDFAllowsDocumentAssembly
コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
コメント注釈 (*64*) refMe's PDFAllowsCommenting
フォーム入力 (*128*) refMe's PDFAllowsFormFieldEntry
*)

on run
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
open listDropObject
end run

on open listDropObject
  
  set recordOption to {|0開封PW付与|:999, |1低解像度印刷禁止|:1, |2高解像度印刷禁止|:2, |4文書に変更禁止|:4, |8内容変更禁止|:8, |16コンテンツコピー禁止|:16, |32補助装置利用禁止|:32, |64コメント注釈禁止|:64, |128フォーム入力禁止|:128} as record
  
  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidOptionDict's setDictionary:(recordOption)
  set ocidAllKeys to ocidOptionDict's allKeys()
  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
  set listAllKeys to ocidSortedArray as list
  
  ##############################
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ###スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ###
  set strTitle to "『禁止設定する』オプション選択(複数可)" as text
  set strPrompt to "『禁止設定』するオプションを選択してください\r何も選択しない=全部許可\r何も選択しない場合所有者PWの設定とページ抽出とコンテンツの変更は禁止になります\r\r複数選択はコマンド⌘キーを押しながらクリック" as text
  try
    set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
  on error
log "エラーしました"
return "エラーしました"
    error "エラーしました" number -200
  end try
  if listResponse = {} then
log "何も選択していない"
    set boolOpenPW to false as boolean
    set intAllowNo to 0 as integer
  else if (item 1 of listResponse) is false then
return "キャンセルしました"
    error "キャンセルしました" number -200
  else
    set boolOpenPW to false as boolean
    set intAllowNo to 0 as integer
    repeat with itemResponse in listResponse
      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
      if intValue = 999 then
        set boolOpenPW to true as boolean
      else
        set intAllowNo to intAllowNo + intValue
      end if
    end repeat
  end if
  
  set intAllowNo to (255 - intAllowNo) as integer
  
  ###############################
  ##実際の処理するPDFのURLを格納するリスト
  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ###ドロップされたエイリアスの数だけ繰り返し
  repeat with itemDropObject in listDropObject
    ###処理除外するエイリアスを判定する
    set strFilePaht to (POSIX path of itemDropObject) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    ###フォルダか?判定
    set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    set ocidURLvalue to (item 2 of listURLvalue)
    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
      ###getResourceValueの戻り値がNULLだった場合対策
      if strURLvalue is "" then
        tell application "Finder"
          set objInfo to info for aliasFilePath
          set strURLvalue to type identifier of objInfo as text
        end tell
      end if
      ###UTIがPDFのエイリアスだけ処理する
      if strURLvalue is "com.adobe.pdf" then
        #####PDFDocumentとして読み込み
        set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
        ########################################
        #####暗号化チェック
        set boolEncrypted to ocidChkDoc's isEncrypted()
        if boolEncrypted is true then
          set strMes to "エラー:すでに暗号化されているので変更できません\n暗号化を解除してから再設定してください" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
        end if
        ########################################
        #####ロック確認
        set boolLocked to ocidChkDoc's isLocked()
        if boolLocked is true then
          set strMes to "エラー:すでにパスワードでロックされているので変更できません\nパスワードでロックを解除してから再設定してください" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
        end if
(ocidDropPathURLArray's addObject:(ocidFilePathURL))
      else
        set strMes to "エラー:PDF専用です" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
      end if
    else
      set strMes to "エラー:PDF専用です" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
    end if
  end repeat
  
  repeat with itemPathURL in ocidDropPathURLArray
    set ocidFileName to itemPathURL's lastPathComponent()
    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
    set strDirName to (strBaseFileName & "_PW設定済")
    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
    set ocidDistDirPathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName) isDirectory:(true))
    #同名チェック
    set appFileManager to refMe's NSFileManager's defaultManager()
    set ocidDistDirPath to ocidDistDirPathURL's |path|()
    set boolDirExists to (appFileManager's fileExistsAtPath:(ocidDistDirPath) isDirectory:(true))
    if boolDirExists = true then
      repeat with itemIntNo from 1 to (100) by 1
        set strDirName to (strBaseFileName & "_PW設定済 " & itemIntNo)
        set ocidDistDirPathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName) isDirectory:(true))
        set ocidDistDirPath to ocidDistDirPathURL's |path|()
        set boolExistsDir to (appFileManager's fileExistsAtPath:(ocidDistDirPath) isDirectory:(true))
        if boolExistsDir is false then
          exit repeat
        end if
      end repeat
    else if boolDirExists is false then
log "処理開始します"
    end if
  end repeat
  
  repeat with itemPathURL in ocidDropPathURLArray
    set ocidSavePdfURL to (ocidDistDirPathURL's URLByAppendingPathComponent:(ocidFileName))
    ####ファイル移動先
    set appFileManager to refMe's NSFileManager's defaultManager()
    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
    set listResults to (appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
    ####コピー
    set lisrBoolDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error|:(reference))
    #####PDFDocumentとして読み込み
    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
    ########################################
    #####パスワード生成 UUIDを利用
    set strTextFileName to strBaseFileName & ".PassWord.txt"
    set ocidTextFilePathURL to (ocidDistDirPathURL's URLByAppendingPathComponent:strTextFileName)
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strOwnerPassword to ocidUUIDString as text
    ##保存用テキストにする
    set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n" as text
    if boolOpenPW is true then
      #####生成したUUIDからハイフンを取り除く
      set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
      set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
      set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
      ##保存用テキストにする
      set strUserPassword to ocidUUIDString as text
      set strTextFile to strTextFile & "利用者用Pw(他者に教える場合はこちら↓)\n" & strUserPassword & "\n" as text
    end if
    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
    ##PWをテキストで保存する
    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
    ########################################
    #####保存OPTION
    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    if boolOwnerPW = true then
(ocidOptionDict's setObject:(strOwnerPassword) forKey:(refMe's PDFDocumentOwnerPasswordOption))
    end if
    if boolOpenPW = true then
      ####開封パスワード
(ocidOptionDict's setObject:(strUserPassword) forKey:(refMe's PDFDocumentUserPasswordOption))
    end if
    ###セキュリティ設定
(ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
    ##################
    ###保存
    ##################
    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
  end repeat
end open

|

[PDFkit]暗号化機能制限解除(所有者パスワードは必要) 修正しました



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


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

#!/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 appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidFalse to (refMe's NSNumber's numberWithBool:false)
set ocidTrue to (refMe's NSNumber's numberWithBool:true)


####何が前面か
tell application "System Events"
  set strAppTitile to title of (front process whose frontmost is true)
end tell
if strAppTitile is "プレビュー" then
  tell application "Preview"
    tell document 1
      set strFilePath to path as text
close
    end tell
  end tell
  ###開いているファイルパスをリストに追加
  set aliasFilePath to POSIX file of strFilePath as alias
else if strAppTitile is "Acrobat Reader" then
  tell application id "com.adobe.Reader"
activate
    ##ファイルパス
    tell active doc
      try
        set aliasFilePath to file alias
log aliasFilePath
      on error
        set strMes to "エラー:ファイルが開いていません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "ファイルが選ばれていません"
      end try
    end tell
  end tell
  ###開いているファイルパスをリストに追加
  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
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
  end if
  
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set aliasFilePath to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI without invisibles, multiple selections allowed and showing package contents) as alias
end if
###パス
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)
#####PDFDocumentとして読み込み
set ocidActiveDoc to (refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL)
###
set boolEnc to ocidActiveDoc's isEncrypted
if boolEnc = ocidFalse then
  set boolLock to ocidActiveDoc's isLocked
  if boolLock = ocidFalse then
return "暗号化もロックもされていません"
  end if
end if
########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strResponse to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strResponse to ocidReadString as text
  else
log "テキストなし"
    set strResponse to "PDFの所有者の暗号化解除パスワード" as text
  end if
end if
try
  set aliasIconPath to POSIX file "/System/Applications/Preview.app/Contents/Resources/AppIcon.icns" as alias
  set recordResponse to (display dialog "PDFの所有者の暗号化解除パスワード" with title "パスワード入力" default answer strResponse 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 strPW to (text returned of recordResponse) as text
else
log "エラーしました"
return "エラーしました"
  error number -128
end if




###拡張子とって
set ocidBaseFilePath to ocidFilePathURL's URLByDeletingPathExtension()
###拡張子を取ったファイル名
set strFileName to ocidBaseFilePath's lastPathComponent() as text
###保存用の新しいファイル名
set strNewFileName to strFileName & ".decrypt" & ".pdf" as text
####元ファイルのコンテナ
set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
###コンテナに新しいファイル名追加して新しいファイルのURL
set ocidSaveFilePathURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strNewFileName) isDirectory:false)

(ocidActiveDoc's unlockWithPassword:(strPW))
#必要なデータを取得
set ocidOutLine to ocidActiveDoc's outlineRoot()
set ocidAttribute to ocidActiveDoc's documentAttributes()
###新しいPDFへ↑のデータを付与
set ocidSaveDoc to refMe's PDFDocument's alloc()'s init()
(ocidSaveDoc's setOutlineRoot:(ocidOutLine))
(ocidSaveDoc's setDocumentAttributes:(ocidAttribute))
###ページ数数えて
set numCntAllPage to ocidActiveDoc's pageCount() as integer
##全ページ取得
repeat with itemIntNo from 0 to (numCntAllPage - 1) by 1
  #暗号化PDFからページを取り出して
  set ocidPDFpage to (ocidActiveDoc's pageAtIndex:(itemIntNo))
  #保存するPDFにセットしていく
(ocidSaveDoc's insertPage:(ocidPDFpage) atIndex:(itemIntNo))
end repeat

###保存する
set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentOwnerPasswordOption))
(ocidOptionDict's setValue:(missing value) forKey:(refMe's PDFDocumentUserPasswordOption))
#(ocidOptionDict's setValue:(true) forKey:(refMe's PDFDocumentOptimizeImagesForScreenOption))
# (ocidOptionDict's setValue:(1) forKey:(refMe's PDFPageImageInitializationOptionCompressionQuality))
set boolDone to (ocidSaveDoc's writeToURL:(ocidSaveFilePathURL) withOptions:(ocidOptionDict))
ocidActiveDoc's release()





|

PDFパスワード設定 ドロップレット(改良)



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


アクセス権を選べるように変更した
PDFの開封パスワードの設定の有無を選べるようにした

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

#!/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 "QuartzCore"
use framework "CoreGraphics"
use scripting additions

property refMe : a reference to current application

####所有者パスワード
property boolOwnerPW : true as boolean
####アクアセス権
## property intAllowNo : 0 as integer
(*
例:全部OKの場合 255 全部ロックは0
許可する番号を『足し算』する
低解像度印刷 (*1*) PDFAllowsLowQualityPrinting
高解像度印刷 (*2*) refMe's PDFAllowsHighQualityPrinting
文書に変更 (*4*) refMe's PDFAllowsDocumentChanges
アッセンブリ (*8*) refMe's PDFAllowsDocumentAssembly
コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
コメント注釈 (*64*) refMe's PDFAllowsCommenting
フォーム入力 (*128*) refMe's PDFAllowsFormFieldEntry
*)

on run
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
open listDropObject
end run

on open listDropObject
  
  set recordOption to {|0開封PW有|:999, |1低解像度印刷|:1, |2高解像度印刷|:2, |4文書に変更|:4, |8内容変更|:8, |16コンテンツコピー|:16, |32補助装置利用可|:32, |64コメント注釈|:64, |128フォーム入力|:128} as record
  
  set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidOptionDict's setDictionary:(recordOption)
  set ocidAllKeys to ocidOptionDict's allKeys()
  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
  set listAllKeys to ocidSortedArray as list
  
  ##############################
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ###スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ###
  set strTitle to "『許可する』オプション選択(複数可)" as text
  set strPrompt to "『許可』するオプションを選択してください\r何も選択しない=何も許可しない=見るだけになります\r\r複数選択はコマンド⌘キーを押しながらクリック" as text
  try
    set listResponse to (choose from list listAllKeys with title strTitle with prompt strPrompt default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
  on error
    log "エラーしました"
return "エラーしました"
    error "エラーしました" number -200
  end try
  if listResponse = {} then
    log "何も選択していない"
    set boolOpenPW to false as boolean
    set intAllowNo to 0 as integer
  else if (item 1 of listResponse) is false then
return "キャンセルしました"
    error "キャンセルしました" number -200
  else
    set boolOpenPW to false as boolean
    set intAllowNo to 0 as integer
    repeat with itemResponse in listResponse
      set intValue to (ocidOptionDict's valueForKey:(itemResponse)) as integer
      if intValue = 999 then
set boolOpenPW to true as boolean
      else
set intAllowNo to intAllowNo + intValue
      end if
    end repeat
  end if
  
  
  
  ###############################
  ##実際の処理するPDFのURLを格納するリスト
  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ###ドロップされたエイリアスの数だけ繰り返し
  repeat with itemDropObject in listDropObject
    ###処理除外するエイリアスを判定する
    set strFilePaht to (POSIX path of itemDropObject) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    ###フォルダか?判定
    set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    set ocidURLvalue to (item 2 of listURLvalue)
    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
      ###getResourceValueの戻り値がNULLだった場合対策
      if strURLvalue is "" then
tell application "Finder"
set objInfo to info for aliasFilePath
set strURLvalue to type identifier of objInfo as text
end tell
      end if
      ###UTIがPDFのエイリアスだけ処理する
      if strURLvalue is "com.adobe.pdf" then
#####PDFDocumentとして読み込み
set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
########################################
#####暗号化チェック
set boolEncrypted to ocidChkDoc's isEncrypted()
if boolEncrypted is true then
set strMes to "エラー:すでに暗号化されているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
########################################
#####ロック確認
set boolLocked to ocidChkDoc's isLocked()
if boolLocked is true then
set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
(ocidDropPathURLArray's addObject:(ocidFilePathURL))
      else
set strMes to "エラー:PDF専用です" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
      end if
    else
      set strMes to "エラー:PDF専用です" as text
      display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
    end if
  end repeat
  
  
  repeat with itemPathURL in ocidDropPathURLArray
    set ocidFileName to itemPathURL's lastPathComponent()
    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
    ###PW設定は複製したPDFに対して行うため保存先ディレクトリを作る
    set strDirName to (strBaseFileName & "_PW設定済")
    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
    ####ファイル移動先
    set appFileManager to refMe's NSFileManager's defaultManager()
    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
    set listResults to (appFileManager's createDirectoryAtURL:ocidDistFolderURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
    ####コピー
    set lisrBoolDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error|:(reference))
    #####PDFDocumentとして読み込み
    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
    ########################################
    #####パスワード生成 UUIDを利用
    set strTextFileName to strBaseFileName & ".pw.txt"
    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strOwnerPassword to ocidUUIDString as text
    ##保存用テキストにする
    set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n" as text
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    ##保存用テキストにする
    set strUserPassword to ocidUUIDString as text
    set strTextFile to strTextFile & "利用者用Pw(他者に教える場合はこちら↓)\n" & strUserPassword & "\n" as text
    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
    ##PWをテキストで保存する
    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
    ########################################
    #####保存OPTION
    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    if boolOwnerPW = true then
(ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
    end if
    if boolOpenPW = true then
      ####開封パスワード
(ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
    end if
    ###セキュリティ設定
(ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
    ##################
    ###保存
    ##################
    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
  end repeat
end open

|

PDFパスワード設定 ドロップレット チョイ修正



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


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

#!/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 "QuartzCore"
use framework "CoreGraphics"
use scripting additions

property refMe : a reference to current application

####開封パスワード
property boolOpenPW : true as boolean
####所有者パスワード
property boolOwnerPW : true as boolean
####アクアセス権
property intAllowNo : 0 as integer
(*
例:全部OKの場合 255 全部ロックは0
許可する番号を『足し算』する
低解像度印刷 (*1*) PDFAllowsLowQualityPrinting
高解像度印刷 (*2*) refMe's PDFAllowsHighQualityPrinting
文書に変更 (*4*) refMe's PDFAllowsDocumentChanges
アッセンブリ (*8*) refMe's PDFAllowsDocumentAssembly
コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
コメント注釈 (*64*) refMe's PDFAllowsCommenting
フォーム入力 (*128*) refMe's PDFAllowsFormFieldEntry
*)

on run
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
open listDropObject
end run

on open listDropObject
  ##
  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ###
  repeat with itemDropObject in listDropObject
    ###
    set strFilePaht to (POSIX path of itemDropObject) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    set ocidURLvalue to (item 2 of listURLvalue)
    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
      if strURLvalue is "" then
tell application "Finder"
set objInfo to info for aliasFilePath
set strURLvalue to type identifier of objInfo as text
end tell
      end if
      if strURLvalue is "com.adobe.pdf" then
#####PDFDocumentとして読み込み
set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
########################################
#####暗号化チェック
set boolEncrypted to ocidChkDoc's isEncrypted()
if boolEncrypted is true then
set strMes to "エラー:すでに暗号化されているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
########################################
#####ロック確認
set boolLocked to ocidChkDoc's isLocked()
if boolLocked is true then
set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
(ocidDropPathURLArray's addObject:(ocidFilePathURL))
      else
set strMes to "エラー:PDF専用です" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
      end if
    else
      set strMes to "エラー:PDF専用です" as text
      display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
    end if
  end repeat
  
  
  repeat with itemPathURL in ocidDropPathURLArray
    set ocidFileName to itemPathURL's lastPathComponent()
    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
    set strDirName to (strBaseFileName & "_PW設定済")
    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
    ####ファイル移動先
    set appFileManager to refMe's NSFileManager's defaultManager()
    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
    set listResults to (appFileManager's createDirectoryAtURL:ocidDistFolderURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
    ####コピー
    set lisrBoolDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error|:(reference))
    #####PDFDocumentとして読み込み
    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
    ########################################
    #####パスワード生成 UUIDを利用
    set strTextFileName to strBaseFileName & ".pw.txt"
    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strOwnerPassword to ocidUUIDString as text
    set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n" as text
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strUserPassword to ocidUUIDString as text
    set strTextFile to strTextFile & "利用者用(他者に教える場合はこちら)Pw\n" & strUserPassword & "\n" as text
    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
    ########################################
    #####OPTION
    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    if boolOwnerPW = true then
(ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
    end if
    if boolOpenPW = true then
      ####開封パスワード
(ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
    end if
    
    ###セキュリティ設定
(ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
    ##################
    ###保存
    ##################
    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
    
    
    
  end repeat
  
  
end open

|

PDFパスワード設定 ドロップレット



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


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

#!/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 "QuartzCore"
use framework "CoreGraphics"
use scripting additions

property refMe : a reference to current application

####開封パスワード
property boolOpenPW : true as boolean
####所有者パスワード
property boolOwnerPW : true as boolean
####アクアセス権
property intAllowNo : 0 as integer
(*
例:全部OKの場合 255 全部ロックは0
許可する番号を『足し算』する
低解像度印刷 (*1*) PDFAllowsLowQualityPrinting
高解像度印刷 (*2*) refMe's PDFAllowsHighQualityPrinting
文書に変更 (*4*) refMe's PDFAllowsDocumentChanges
アッセンブリ (*8*) refMe's PDFAllowsDocumentAssembly
コンテンツコピー(*16*) refMe's PDFAllowsContentCopying
アクセシビリティ(*32*) refMe's PDFAllowsContentAccessibility
コメント注釈 (*64*) refMe's PDFAllowsCommenting
フォーム入力 (*128*) refMe's PDFAllowsFormFieldEntry
*)

on run
  ###ダイアログを前面に出す
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set listDropObject to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
open listDropObject
end run

on open listDropObject
  ##
  set ocidDropPathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ###
  repeat with itemDropObject in listDropObject
    ###
    set strFilePaht to (POSIX path of itemDropObject) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePaht))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    set ocidURLvalue to (item 2 of listURLvalue)
    if ocidURLvalue = (refMe's NSNumber's numberWithBool:false) then
      set listURLvalue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set strURLvalue to (item 2 of listURLvalue)'s identifier() as text
      if strURLvalue is "" then
tell application "Finder"
set objInfo to info for aliasFilePath
set strURLvalue to type identifier of objInfo as text
end tell
      end if
      if strURLvalue is "com.adobe.pdf" then
#####PDFDocumentとして読み込み
set ocidChkDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidFilePathURL))
########################################
#####暗号化チェック
set boolEncrypted to ocidChkDoc's isEncrypted()
if boolEncrypted is true then
set strMes to "エラー:すでに暗号化されているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
########################################
#####ロック確認
set boolLocked to ocidChkDoc's isLocked()
if boolLocked is true then
set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return strMes
end if
(ocidDropPathURLArray's addObject:(ocidFilePathURL))
      end if
    end if
  end repeat
  
  
  repeat with itemPathURL in ocidDropPathURLArray
    set ocidFileName to itemPathURL's lastPathComponent()
    set strBaseFileName to ocidFileName's stringByDeletingPathExtension() as text
    set strDirName to (strBaseFileName & "_PW設定済")
    set ocidContainerDirURL to itemPathURL's URLByDeletingLastPathComponent()
    set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:(strDirName))
    set ocidSavePdfURL to (ocidDistFolderURL's URLByAppendingPathComponent:(ocidFileName))
    ####ファイル移動先
    set appFileManager to refMe's NSFileManager's defaultManager()
    set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
    set listResults to (appFileManager's createDirectoryAtURL:ocidDistFolderURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
    ####コピー
    set lisrBoolDone to (appFileManager's copyItemAtURL:(itemPathURL) toURL:(ocidSavePdfURL) |error|:(reference))
    #####PDFDocumentとして読み込み
    set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:(ocidSavePdfURL))
    ########################################
    #####パスワード生成 UUIDを利用
    set strTextFileName to strBaseFileName & ".pw.txt"
    set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strOwnerPassword to ocidUUIDString as text
    set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n" as text
    #####生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strUserPassword to ocidUUIDString as text
    set strTextFile to strTextFile & "利用者用(他者に教える場合はこちら)Pw\n" & strUserPassword & "\n" as text
    set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
    set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
    ########################################
    #####OPTION
    set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    if boolOwnerPW = true then
(ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
    end if
    if boolOpenPW = true then
      ####開封パスワード
(ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
    end if
    
    ###セキュリティ設定
(ocidOptionDict's setObject:(intAllowNo) forKey:(refMe's PDFDocumentAccessPermissionsOption))
    ##################
    ###保存
    ##################
    set boolResults to (ocidActivDoc's writeToURL:(ocidSavePdfURL) withOptions:(ocidOptionDict))
    
    
    
  end repeat
  
  
end open

|

CGPDFContextで暗号化とパスワード設定



最新版・修正版はカテゴリートップから見ていってください
PDFKit DocumentPermissions


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

#!/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 "QuartzCore"
use framework "CoreGraphics"
use framework "WebKit"
use scripting additions


property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidFalse to (refMe's NSNumber's numberWithBool:false)
set ocidTrue to (refMe's NSNumber's numberWithBool:true)

set listAliasFilePath to {} as list

####何が前面か
tell application "System Events"
  set strAppTitile to title of (front process whose frontmost is true)
end tell
if strAppTitile is "プレビュー" then
  tell application "Preview"
    tell document 1
      set strFilePath to path as text
      close
    end tell
  end tell
  ###開いているファイルパスをリストに追加
  set aliasFilePath to POSIX file of strFilePath as alias
  copy aliasFilePath to end of listAliasFilePath
else if strAppTitile is "Acrobat Reader" then
  tell application id "com.adobe.Reader"
    activate
    ##ファイルパス
    tell active doc
      try
        set aliasFilePath to file alias
        log aliasFilePath
      on error
        set strMes to "エラー:ファイルが開いていません" as text
        display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
        return "ファイルが選ばれていません"
      end try
    end tell
  end tell
  ###開いているファイルパスをリストに追加
  copy aliasFilePath to end of listAliasFilePath
  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
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
  end if
  set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidUserDesktopPath to ocidUserDesktopPathArray's objectAtIndex:0
  set listChooseFileUTI to {"com.adobe.pdf"}
  set strPromptText to "PDFファイルを選んでください" as text
  set listAliasFilePath to (choose file with prompt strPromptText default location (ocidUserDesktopPath as alias) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
end if
####リストに格納されているファイルパスを数えて
set numCntFilePath to (count of listAliasFilePath) as integer
if numCntFilePath = 0 then
  set strMes to "エラー:ファイルが開いていません" as text
  display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
  return "ファイルが選ばれていません"
end if

#######################################
###書類の数だけ繰り返し
#######################################
repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath 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)
  #####PDFDocumentとして読み込み
  set ocidActivDoc to (refMe's PDFDocument's alloc()'s initWithURL:ocidFilePathURL)
  ########################################
  #####暗号化チェック
  set boolEncrypted to ocidActivDoc's isEncrypted()
  if boolEncrypted is true then
    set strMes to "エラー:すでに暗号化されているので変更できません" as text
    display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
    return strMes
  end if
  ########################################
  #####ロック確認
  set boolLocked to ocidActivDoc's isLocked()
  if boolLocked is true then
    set strMes to "エラー:すでにパスワードでロックされているので変更できません" as text
    display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
    return strMes
  end if
  ####ファイルパス
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  set strFileName to ocidFileName as text
  set coidBaseFileName to ocidFileName's stringByDeletingPathExtension()
  set ocidContainerDirURL to ocidFilePathURL's URLByDeletingLastPathComponent()
  set ocidDistFolderURL to (ocidContainerDirURL's URLByAppendingPathComponent:coidBaseFileName)
  ####ファイル移動先
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  (ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions))
  set listResults to (appFileManager's createDirectoryAtURL:ocidDistFolderURL withIntermediateDirectories:true attributes:ocidAttrDict |error|:(reference))
  ########################################
  #####パスワード生成 UUIDを利用
  set strTextFileName to strFileName & ".pw.txt"
  set ocidTextFilePathURL to (ocidDistFolderURL's URLByAppendingPathComponent:strTextFileName)
  #####生成したUUIDからハイフンを取り除く
  set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
  set ocidConcreteUUID to refMe's NSUUID's UUID()
  (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
  set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
  (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
  set strOwnerPassword to ocidUUIDString as text
  set strTextFile to "所有者用Pw\n" & strOwnerPassword & "\n\n" as text
  #####生成したUUIDからハイフンを取り除く
  set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
  set ocidConcreteUUID to refMe's NSUUID's UUID()
  (ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
  set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
  (ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
  set strUserPassword to ocidUUIDString as text
  set strTextFile to strTextFile & "利用者用(他者に教える場合はこちら)Pw\n" & strUserPassword & "\n" as text
  set ocidPWString to (refMe's NSString's stringWithString:strTextFile)
  set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
  set boolResults to (ocidUUIDData's writeToURL:ocidTextFilePathURL atomically:true)
  ########################################
  #####OPTION
  set ocidOptionDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
  ########################################
  #####通常はこの方法でアクセス権付与する
  ####(ocidOptionDict's setObject:strOwnerPassword forKey:(refMe's PDFDocumentOwnerPasswordOption))
  ####開封パスワード コメントアウトで開封パスワード無しになります
  ####  (ocidOptionDict's setObject:strUserPassword forKey:(refMe's PDFDocumentUserPasswordOption))
  #####PDFDocumentAccessPermissionsOption
  ####(*1*) PDFAllowsLowQualityPrinting 
  ####(*2*) refMe's PDFAllowsHighQualityPrinting
  ####(*4*) refMe's PDFAllowsDocumentChanges
  ####(*8*) refMe's PDFAllowsDocumentAssembly
  ####(*16*) refMe's PDFAllowsContentCopying
  ####(*32*) refMe's PDFAllowsContentAccessibility 
  ####(*64*) refMe's PDFAllowsCommenting 
  ####(*128*) refMe's PDFAllowsFormFieldEntry 
  ###全部禁止の場合は0
  ###(ocidOptionDict's setObject:0 forKey:(refMe's PDFDocumentAccessPermissionsOption))
  ###例 印刷OKの場合は2
  ##  (ocidOptionDict's setObject:0 forKey:(refMe's PDFDocumentAccessPermissionsOption))
  ########################################
  ####CGPDFContextで暗号化とパスワード設定する
  ###暗号化の深度デフォルトは40だって(8 between 40 and 128)
  (ocidOptionDict's setObject:(128 as number) forKey:"kCGPDFContextEncryptionKeyLength")
  ###印刷禁止-->コンテンツ:ページの抽出も出来ません
  (ocidOptionDict's setObject:ocidFalse forKey:"kCGPDFContextAllowsPrinting")
  ###コピー禁止
  (ocidOptionDict's setObject:ocidFalse forKey:"kCGPDFContextAllowsCopying")
  ###閲覧パスワードを付与する場合はコメント外す
  ###(ocidOptionDict's setObject:(strUserPassword as text) forKey:"kCGPDFContextUserPassword")
  ###所有者パスワード
  (ocidOptionDict's setObject:(strOwnerPassword as text) forKey:"kCGPDFContextOwnerPassword")
  
  ##################
  ###保存
  ##################
  set boolResults to (ocidActivDoc's writeToURL:ocidFilePathURL withOptions:ocidOptionDict)
  
  ###PDFファイル移動
  set ocidPdfFilePath to (ocidDistFolderURL's URLByAppendingPathComponent:ocidFileName)
  set listResults to (appFileManager's moveItemAtURL:ocidFilePathURL toURL:ocidPdfFilePath |error|:(reference))
  
  
end repeat


return
########################################
#### 開く  テキストエディットで開く場合
set strSaveRTFPath to ocidSaveRTFURL's |path|() as text
tell application "TextEdit"
  activate
  open (ocidSaveHTMLURL as alias)
  
  (* リッチテキストがいい場合はこっち
tell front document
save in strSaveRTFPath
end tell
tell front document
close
end tell
open ocidSaveRTFURL as alias
  *)
end tell

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings 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 Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom