20260523

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

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

NOTE記事一覧ですnote.com
 

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

ビデオのpxサイズ取得avmediainfo.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
004(*
005
006avmediainfoコマンドを使うが
007パスのエスケープのみFoundationを利用している
008
009com.cocolog-nifty.quicktimer.icefloe *)
010----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
011use AppleScript version "2.8"
012use framework "Foundation"
013use scripting additions
014property refMe : a reference to current application
015
016
017
018#############################
019###入力ファイル
020#############################
021tell current application
022   set strName to name as text
023end tell
024if strName is "osascript" then
025   tell application "Finder" to activate
026else
027   tell current application to activate
028end if
029#デスクトップ
030set aliasDesktopDirPath to (path to desktop from user domain) as alias
031set listUTI to {"public.movie"} as list
032set strTitle to ("ファイル選択") as text
033set strPrompt to ("ムービーファイルを選んでください") as text
034tell application "SystemUIServer"
035   activate
036   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
037end tell
038
039#ソート 名前順
040tell application "Finder"
041   set listSortedFilePath to (sort of listAliasFilePath by name) as alias list
042end tell
043
044#エイリアスリストの中のパスの数
045set numCntList to (count of listSortedFilePath) as integer
046
047repeat with itemIntNo from 1 to numCntList by 1
048   #開くムービーのエイリアス・パスをエイリアスリストから取得して
049   set aliasItemFilePath to (item itemIntNo of listSortedFilePath) as alias
050   set strFileName to (name of (info for aliasItemFilePath)) as text
051   #UNIXパスにして
052   set strFilePath to (POSIX path of aliasItemFilePath) as text
053   set strFilePath to doPathEscape(strFilePath)
054   #コマンド実行して
055   set strCmd to ("/usr/bin/avmediainfo \"" & strFilePath & "\" | grep \"Dimensions:\" | grep -v \"Presentation\"") as text
056   set strStdOut to (do shell script strCmd) as text
057   #戻り値をスペースで分割してリストにする
058   set strDelim to AppleScript's text item delimiters
059   set AppleScript's text item delimiters to space
060   set listDimensions to every text item of strStdOut
061   set AppleScript's text item delimiters to strDelim
062   set strWpx to (second item of listDimensions) as text
063   set strHpx to (last item of listDimensions) as text
064   log strWpx
065   log strHpx
066end repeat
067
068
069return
070
071
072
073########################
074#パスのエスケープ
075to doPathEscape(strFilePath)
076   set strFilePath to strFilePath as text
077   set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
078   set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
079   set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)
080   set listEscChar to {"\\", "\"", "$", "`"} as list
081   repeat with itemEscChar in listEscChar
082      set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:(itemEscChar) withString:("\\" & itemEscChar & ""))
083   end repeat
084   set ocidFilePath to (ocidFilePath's stringByReplacingOccurrencesOfString:("!") withString:("\"'!'\""))
085   
086   return ocidFilePath
087end doPathEscape
AppleScriptで生成しました