| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | avmediainfoコマンドを使うが |
| 007 | パスのエスケープのみFoundationを利用している |
| 008 |
|
| 009 | com.cocolog-nifty.quicktimer.icefloe *) |
| 010 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 011 | use AppleScript version "2.8" |
| 012 | use framework "Foundation" |
| 013 | use scripting additions |
| 014 | property refMe : a reference to current application |
| 015 |
|
| 016 |
|
| 017 |
|
| 018 | ############################# |
| 019 | ###入力ファイル |
| 020 | ############################# |
| 021 | tell current application |
| 022 | set strName to name as text |
| 023 | end tell |
| 024 | if strName is "osascript" then |
| 025 | tell application "Finder" to activate |
| 026 | else |
| 027 | tell current application to activate |
| 028 | end if |
| 029 | #デスクトップ |
| 030 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 031 | set listUTI to {"public.movie"} as list |
| 032 | set strTitle to ("ファイル選択") as text |
| 033 | set strPrompt to ("ムービーファイルを選んでください") as text |
| 034 | tell 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 |
| 037 | end tell |
| 038 |
|
| 039 | #ソート 名前順 |
| 040 | tell application "Finder" |
| 041 | set listSortedFilePath to (sort of listAliasFilePath by name) as alias list |
| 042 | end tell |
| 043 |
|
| 044 | #エイリアスリストの中のパスの数 |
| 045 | set numCntList to (count of listSortedFilePath) as integer |
| 046 |
|
| 047 | repeat 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 |
| 066 | end repeat |
| 067 |
|
| 068 |
|
| 069 | return |
| 070 |
|
| 071 |
|
| 072 |
|
| 073 | ######################## |
| 074 | #パスのエスケープ |
| 075 | to 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 |
| 087 | end doPathEscape |