AppleScript XMP

[xmp]XMPデータ書き出し


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

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

サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use scripting additions
010
011property refMe : a reference to current application
012
013set appFileManager to refMe's NSFileManager's defaultManager()
014
015#############################
016###ダイアログを前面に出す
017set strName to (name of current application) as text
018if strName is "osascript" then
019  tell application "Finder" to activate
020else
021  tell current application to activate
022end if
023############ デフォルトロケーション
024set appFileManager to refMe's NSFileManager's defaultManager()
025set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
026set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
027set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
028###ANY
029set listUTI to {"public.data"}
030set strMes to ("ファイルを選んでください") as text
031set strPrompt to ("ファイルを選んでください") as text
032try
033  ### ファイル選択時
034  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
035on error
036  log "エラーしました"
037  return "エラーしました"
038end try
039#入力ファイル
040set strFilePath to (POSIX path of aliasFilePath) as text
041set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
042set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
043set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
044#出力ファイル
045set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
046set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:("xmp")
047set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text
048#コマンド
049try
050  set strCommandText to ("/usr/bin/awk  -v start=\"<x:xmpmeta\" -v end=\"</x:xmpmeta>\" '$0 ~ start, $0 ~ end' \"" & strFilePath & "\"") as text
051  set strResponse to (do shell script strCommandText) as text
052on error
053  return "エラーしました"
054end try
055#保存
056set ocidReadXMP to refMe's NSString's stringWithString:(strResponse)
057set ocidOption to (refMe's NSUTF8StringEncoding)
058set listDone to ocidReadXMP's writeToURL:(strSaveFilePath) atomically:(true) encoding:(ocidOption) |error| :(reference)
059#終了
060if (item 1 of listDone) is true then
061  log "正常処理"
062  return "正常処理"
063else if (item 2 of listDone) ≠ (missing value) then
064  log (item 2 of listDone)'s code() as text
065  log (item 2 of listDone)'s localizedDescription() as text
066  return "エラーしました"
067end if
068
069
AppleScriptで生成しました

|

[PDF]メタデータ タイトル設定


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
exiftoolが別途必要です
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-e7e51d.html

*)
# 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 strBinPath to ("/usr/local/bin/exiftool") as text --通常はこちら
set strBinPath to ("~/bin/exiftool/exiftool") as text


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


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

#######################################
## クリップボードの中身取り出し
#######################################
###初期化
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 strReadString 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 strReadString to ocidReadString as text
  else
log "テキストなし"
    set aliasFirstFilePath to (item 1 of listAliasFilePath) as alias
    tell application "Finder"
      set strFirstFileName to name of aliasFirstFilePath as text
    end tell
    set strReadString to strFirstFileName as text
  end if
end if
########################
##ダイアログを前面に出す
set strName to (name of current application) as text
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
########################
##ダイアログ
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("タイトルを入力してください\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)
if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set ocidReturnedText to refMe's NSString's stringWithString:(strReturnedText)
########################
##改行を取る
set ocidReturned to ocidReturnedText's stringByReplacingOccurrencesOfString:("\r") withString:("")
set ocidReturnedText to ocidReturned's stringByReplacingOccurrencesOfString:("\n") withString:("")
set strSetText to ocidReturnedText as string
#####BIN path
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set ocidBinPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidBinPath) isDirectory:false)
set strBinPath to ocidBinPathURL's |path| as text


#######################################
###ダイアログで選択した書類の数だけ繰り返し
#######################################
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 strFileName to ocidFilePath's lastPathComponent() as text
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  #####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 "エラー:" & strFileName & "暗号化されています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "暗号化されているので変更できません"
  end if
  ########################################
  #####ロック確認
  set boolLocked to ocidActivDoc's isLocked()
  if boolLocked is true then
    set strMes to "エラー:" & strFileName & "パスワードでロックされています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "パスワードでロックされているので変更できません"
  end if
  ########################################
  #####アトリビュートを取得して
  set ocidAttributes to ocidActivDoc's documentAttributes()
  ######可変ディクショナリに格納
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithDictionary:ocidAttributes)
log ocidAttrDict as record
  ###Titleキーの内容を設定
(ocidAttrDict's setValue:(ocidReturnedText) forKey:"Title")
(ocidAttrDict's setValue:"" forKey:"Creator")
  #####値を変更したレコードをセットする
(ocidActivDoc's setDocumentAttributes:ocidAttrDict)
  ##################
  ###保存
  ##################
(ocidActivDoc's writeToURL:ocidFilePathURL)
  ####解放
  set ocidActivDoc to ""
  set ocidDocAttrDict to ""
  ##################
  ### exifToolでXMPを削除
  ##################
  set strCommandText to ("\"" & strBinPath & "\" -m -overwrite_original -title=\"" & strSetText & "\" -xmp:Title=\"" & strSetText & "\" -xmp:dc:Title=\"" & strSetText & "\" -IPTC:ObjectName=\"" & strSetText & "\" \"" & strFilePath & "\"") as text
  try
do shell script strCommandText
  end try
end repeat


return "処理終了"






|

[exiftool]PDFのメタデータ全部削除


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
exiftoolが別途必要です
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-e7e51d.html

*)
# 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 strBinPath to ("/usr/local/bin/exiftool") as text --通常はこちら
set strBinPath to ("~/bin/exiftool/exiftool") as text


set objFileManager to refMe's NSFileManager's defaultManager()
#
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set ocidBinPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidBinPath) isDirectory:false)
set strBinPath to ocidBinPathURL's |path| as text

##############################
#####ダイアログを前面に出す
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 ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias
tell application "Finder"
end tell
set listChooseFileUTI to {"com.adobe.pdf"}
set strPromptText to "PDFファイルを選んでください" as text
set listAliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and multiple selections allowed without showing package contents) as list
#######################################
###ダイアログで選択した書類の数だけ繰り返し
#######################################
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 strFileName to ocidFilePath's lastPathComponent() as text
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false)
  #####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 "エラー:" & strFileName & "暗号化されています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "暗号化されているので変更できません"
  end if
  ########################################
  #####ロック確認
  set boolLocked to ocidActivDoc's isLocked()
  if boolLocked is true then
    set strMes to "エラー:" & strFileName & "パスワードでロックされています" as text
display alert strMes buttons {"OK", "キャンセル"} default button "OK" as informational giving up after 3
return "パスワードでロックされているので変更できません"
  end if
  ########################################
  #####アトリビュートを取得して
  set ocidAttributes to ocidActivDoc's documentAttributes()
  ######可変ディクショナリに格納
  set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithDictionary:ocidAttributes)
log ocidAttrDict as record
  ###Titleキーの内容をブランクにする
(ocidAttrDict's setValue:"" forKey:"Title")
(ocidAttrDict's setValue:"" forKey:"Creator")
(ocidAttrDict's setValue:"" forKey:"Author")
(ocidAttrDict's setValue:"" forKey:"Keywords")
(ocidAttrDict's setValue:"" forKey:"Producer")
(ocidAttrDict's setValue:"" forKey:"Subject")
(ocidAttrDict's setValue:"" forKey:"ModificationDate")
(ocidAttrDict's setValue:"" forKey:"CreationDate")
  
  #####値を変更したレコードをセットする
(ocidActivDoc's setDocumentAttributes:ocidAttrDict)
  ##################
  ###保存
  ##################
(ocidActivDoc's writeToURL:ocidFilePathURL)
  ####解放
  set ocidActivDoc to ""
  set ocidDocAttrDict to ""
  ##################
  ### exifToolでXMPを削除
  ##################
  set strCommandText to ("\"" & strBinPath & "\" -overwrite_original -all= \"" & strFilePath & "\"") as text
  try
do shell script strCommandText
  end try
end repeat


return "処理終了"






|

apple-preview:Bookmarks

ちょっと前までは com.apple.Preview.bookmarks.plistでの紐付けだったが
今はXMPメタファイルになった

  <rdf:Description rdf:about=""
   xmlns:xmp="http://ns.adobe.com/xap/1.0/"
   xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
   xmlns:apple-preview="http://ns.apple.com/Preview/1.0/">
   <apple-preview:Bookmarks>
    <rdf:Seq>
     <rdf:li rdf:parseType="Resource">
      <apple-preview:PageIndex>0</apple-preview:PageIndex>
      <apple-preview:UUID>C0900257-4614-4736-98D7-6AFA344DAE19</apple-preview:UUID>
     </rdf:li>
     <rdf:li rdf:parseType="Resource">
      <apple-preview:PageIndex>1</apple-preview:PageIndex>
      <apple-preview:UUID>A9527326-1703-4DCC-8118-73693A7C658B</apple-preview:UUID>
     </rdf:li>
    </rdf:Seq>
   </apple-preview:Bookmarks>
  </rdf:Description>


apple-preview:UUIDで指定されるUUIDの生成方法がわからないため
自動生成はあきらめる

|

その他のカテゴリー

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