| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | Exiftoolを使う方法 |
| 007 | インストールが別途必要 |
| 008 | https://working-penguin.blogspot.com/2026/05/applescriptexiftool.html |
| 009 |
|
| 010 |
|
| 011 |
|
| 012 | com.cocolog-nifty.quicktimer.icefloe *) |
| 013 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 014 | use AppleScript version "2.8" |
| 015 | use framework "Foundation" |
| 016 | use framework "AppKit" |
| 017 | use framework "UniformTypeIdentifiers" |
| 018 | use scripting additions |
| 019 | property refMe : a reference to current application |
| 020 |
|
| 021 | ############################# |
| 022 | # |
| 023 | set strBinFilePath to ("~/Library/Application Support/bin/exiftool/exiftool") as text |
| 024 | set ocidBinFilePathStr to refMe's NSString's stringWithString:(strBinFilePath) |
| 025 | set ocidBinFilePath to ocidBinFilePathStr's stringByStandardizingPath() |
| 026 | set ocidBinFilePath to ocidBinFilePath's stringByExpandingTildeInPath() |
| 027 | set ocidBinFilePathURL to refMe's NSURL's fileURLWithPath:(ocidBinFilePath) isDirectory:(false) |
| 028 |
|
| 029 | ############################# |
| 030 | ###入力ファイル |
| 031 | ############################# |
| 032 | tell current application |
| 033 | set strName to name as text |
| 034 | end tell |
| 035 | if strName is "osascript" then |
| 036 | tell application "Finder" to activate |
| 037 | else |
| 038 | tell current application to activate |
| 039 | end if |
| 040 | #デスクトップ |
| 041 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 042 | set listUTI to {"public.movie"} as list |
| 043 | set strTitle to ("ファイル選択") as text |
| 044 | set strPrompt to ("ムービーファイルを選んでください") as text |
| 045 | tell application "SystemUIServer" |
| 046 | activate |
| 047 | set listAliasFilePath to (choose file with prompt (strPrompt) default location (aliasDesktopDirPath) of type (listUTI) with invisibles, showing package contents and multiple selections allowed) as list |
| 048 | end tell |
| 049 |
|
| 050 | #NSURLのArrayを作成して |
| 051 | set ocidFileURLArrayM to refMe's NSMutableArray's alloc()'s init() |
| 052 |
|
| 053 | repeat with itemAliasFilePath in listAliasFilePath |
| 054 | set aliasFilePath to itemAliasFilePath as alias |
| 055 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 056 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 057 | set ocidFilePathStr to ocidFilePathStr's precomposedStringWithCanonicalMapping() |
| 058 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 059 | set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath() |
| 060 | set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 061 | (ocidFileURLArrayM's addObject:(ocidFilePathURL)) |
| 062 | end repeat |
| 063 |
|
| 064 | #ソート |
| 065 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("path") ascending:(yes) selector:("localizedStandardCompare:") |
| 066 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
| 067 | set ocidFileURLArrayS to ocidFileURLArrayM's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
| 068 |
|
| 069 | #Arrayのアイテム数 |
| 070 | set numCntArray to ocidFileURLArrayS's |count|() |
| 071 |
|
| 072 | repeat with itemIntNo from 0 to (numCntArray - 1) by 1 |
| 073 | #開くムービーのエイリアス・パスをエイリアスリストから取得して |
| 074 | set ocidItemFileURL to (ocidFileURLArrayS's objectAtIndex:(itemIntNo)) |
| 075 | set ocidItemFile to ocidItemFileURL's |path|() |
| 076 | set ocidBinFilePath to ocidBinFilePathURL's |path|() |
| 077 | set ocidItemFile to doPathEscape(ocidItemFile) |
| 078 | set ocidBinFilePath to doPathEscape(ocidBinFilePath) |
| 079 | |
| 080 | set strCmd to ("\"" & ocidBinFilePath & "\" -json \"" & ocidItemFile & "\"") as text |
| 081 | set strStdOut to (do shell script strCmd) as text |
| 082 | # |
| 083 | set ocidStdOut to (refMe's NSMutableString's stringWithString:(strStdOut)) |
| 084 | set ocidJsonData to (ocidStdOut's dataUsingEncoding:(refMe's NSUTF8StringEncoding)) |
| 085 | #JSON ルートがArray |
| 086 | set ocidOption to (refMe's NSJSONReadingJSON5Allowed) |
| 087 | set listResponse to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:(ocidOption) |error|:(reference)) |
| 088 | set ocidJsonDict to (first item of listResponse)'s firstObject() |
| 089 | set numWpx to (ocidJsonDict's objectForKey:("SourceImageWidth")) as integer |
| 090 | set numHpx to (ocidJsonDict's objectForKey:("SourceImageHeight")) as integer |
| 091 | set numWpx to (ocidJsonDict's objectForKey:("ImageWidth")) as integer |
| 092 | set numHpx to (ocidJsonDict's objectForKey:("ImageHeight")) as integer |
| 093 | |
| 094 | log numWpx |
| 095 | log numHpx |
| 096 | |
| 097 | end repeat |
| 098 |
|
| 099 |
|
| 100 | return |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 | ######################## |
| 106 | #パスのエスケープ |
| 107 | to doPathEscape(strFilePath) |
| 108 | set strFilePath to strFilePath as text |
| 109 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
| 110 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 111 | set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false) |
| 112 | set listEscChar to {"\\", "\"", "$", "`"} as list |
| 113 | repeat with itemEscChar in listEscChar |
| 114 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\" & itemEscChar & "")) |
| 115 | end repeat |
| 116 | set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\"'!'\"")) |
| 117 | |
| 118 | return ocidFilePath |
| 119 | end doPathEscape |