Finder上で選択中のHEIC画像から位置情報(緯度、経度)を削除するAppleScriptです。
JEPGのようにEXIF情報を編集するのとはHEIC画像の構造が異なるため、方法については試行錯誤の最中です。いろいろ試してみたところ、HEICの解析を行なっても仕様を追いきれなかったので、メモリ上にHEIC画像を読み込んで、HEIC画像でファイルに書き出し直しています。
また、画像の回転状態を元画像から取得して、自動回転させ、元画像と回転状態を維持しています。
NSImageにHEIC画像を読み込んでファイル書き込みするという方法でも、問題なく処理できることでしょう。
| AppleScript名:Finder上で選択中のHEIC画像から位置情報を削除_v5.scptd |
| — – Created by: Takaaki Naganoya – Created on: 2026/03/16 — – Copyright © 2026 Piyomaru Software, All Rights Reserved — on run tell application "Finder" set targetFilesList to selection as alias list end tell if targetFilesList is {} then display alert "エラー" message "FinderでHEICファイルを選択してください。" return end if set successfulReconstructions to 0 repeat with currentFile in targetFilesList set posixPathString to POSIX path of currentFile if (posixPathString ends with ".heic") or (posixPathString ends with ".HEIC") then set isProcessed to my redrawImageMaintainingOrientation(posixPathString) if isProcessed then set successfulReconstructions to successfulReconstructions + 1 end if end if end repeat display notification (successfulReconstructions as string) & " 個のファイルの位置情報を削除しました。" with title "位置情報抹消完了" end run on redrawImageMaintainingOrientation(posixPath) — Swiftプログラム — 1. 画像データ(CGImage)と回転情報のみを抽出 — 2. 新しい画像として書き出し、回転情報を再設定 — 3. GPS情報は一切含めない set swiftSource to " import Foundation import ImageIO import CoreGraphics let path = \"" & posixPath & "\"let url = URL(fileURLWithPath: path) guard let source = CGImageSourceCreateWithURL(url as CFURL, nil), let count = CGImageSourceGetCount(source) // 元のファイルに新規作成(上書き)としてDestinationを準備 guard let destination = CGImageDestinationCreateWithURL(url as CFURL, type, count, nil) else { exit(1) } for i in 0..<count { if let cgImage = CGImageSourceCreateImageAtIndex(source, i, nil) { // 2. 新しいプロパティを作成(空の辞書) let freshProperties = NSMutableDictionary() // 3. 元のメタデータから「回転情報」だけを取得して引き継ぐ if let orientation = oldProps[kCGImagePropertyOrientation as String] { freshProperties[kCGImagePropertyOrientation as String] = orientation } // カラープロファイル (ColorModel) も維持しないと色が変わるため引き継ぐ } } // 4. 回転情報は維持し、GPSを含まないプロパティで画像を書き込む CGImageDestinationAddImage(destination, cgImage, freshProperties as CFDictionary) } } if CGImageDestinationFinalize(destination) { } else { exit(1) } " try do shell script "swift -e " & quoted form of swiftSource return true on error return false end try end redrawImageMaintainingOrientation |



























