20260523

[applescript] ビデオのpxサイズ取得 mdls コマンドを使う

[applescript] ビデオのpxサイズ取得 mdls コマンドを使う

NOTE記事一覧ですnote.com
 

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

ビデオのpxサイズ取得MDLS+ System Events.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
004(*
005
006mdls を使う場合
007TS=MPEG1ビデオ等で値が取れないのでmp4専用と思った方がいい
008
009
010
011com.cocolog-nifty.quicktimer.icefloe *)
012----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
013use AppleScript version "2.8"
014use framework "Foundation"
015use scripting additions
016property refMe : a reference to current application
017
018
019
020#############################
021###入力ファイル
022#############################
023tell current application
024   set strName to name as text
025end tell
026if strName is "osascript" then
027   tell application "Finder" to activate
028else
029   tell current application to activate
030end if
031#デスクトップ
032set aliasDesktopDirPath to (path to desktop from user domain) as alias
033set listUTI to {"public.movie"} as list
034set strTitle to ("ファイル選択") as text
035set strPrompt to ("ムービーファイルを選んでください") as text
036tell application "SystemUIServer"
037   activate
038   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
039end tell
040
041#ソート 名前順
042tell application "Finder"
043   set listSortedFilePath to (sort of listAliasFilePath by name) as alias list
044end tell
045
046#エイリアスリストの中のパスの数
047set numCntList to (count of listSortedFilePath) as integer
048
049set aliasTempDir to (path to temporary items from user domain) as alias
050set strTempDir to (POSIX path of aliasTempDir) as text
051
052repeat with itemIntNo from 1 to numCntList by 1
053   #開くムービーのエイリアス・パスをエイリアスリストから取得して
054   set aliasItemFilePath to (item itemIntNo of listSortedFilePath) as alias
055   #ファイル名
056   set strFileName to (name of (info for aliasItemFilePath)) as text
057   set strPlistFileName to ("" & strFileName & ".plist") as text
058   set strPlistFilePath to ("" & strTempDir & strPlistFileName & "") as text
059   
060   #UNIXPATH
061   set strItemFilePath to (POSIX path of aliasItemFilePath) as text
062   set strItemFilePathESC to doPathEscape(strItemFilePath) as text
063   set strPlistFilePathESC to doPathEscape(strPlistFilePath) as text
064   #コマンド整形
065   set strCmd to ("/usr/bin/mdls -plist - \"" & strItemFilePathESC & "\" > \"" & strPlistFilePathESC & "\"") as text
066   set strStdOut to (do shell script strCmd) as text
067   
068   
069   #コマンド作成されたPLISTを開いて値を取得する
070   tell application "System Events"
071      tell property list file strPlistFilePath
072         set numWpx to (value of property list item "kMDItemPixelWidth") as integer
073         set numHpx to (value of property list item "kMDItemPixelHeight") as integer
074         set numBitRate to (value of property list item "kMDItemVideoBitRate") as integer
075         set numFileSize to (value of property list item "kMDItemFSSize") as number
076      end tell
077   end tell
078   
079   log numWpx
080   log numHpx
081end repeat
082
083
084return
085
086
087########################
088#パスのエスケープ
089to doPathEscape(strFilePath)
090   set strFilePath to strFilePath as text
091   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
092   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
093   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
094   set listEscChar to {"\\", "\"", "$", "`"} as list
095   repeat with itemEscChar in listEscChar
096      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\" & itemEscChar & ""))
097   end repeat
098   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\"'!'\""))
099   
100   return ocidFilePath
101end doPathEscape
AppleScriptで生成しました